{"action":"created","comment":{"url":"https://api.github.com/repos/emancu/toml-rb/pulls/comments/53760268","id":53760268,"diff_hunk":"@@ -10,26 +10,45 @@ def value\n     # Replace the unicode escaped characters with the corresponding character\n     # e.g. \\u03B4 => ?\n     def self.decode_unicode(str)\n-      str.gsub(/([^\\\\](?:\\\\\\\\)*\\\\u[\\da-f]{4})/i) do |m|\n-        m[0...-6] + [m[-4..-1].to_i(16)].pack('U')\n+      str.gsub(/\\\\u([\\da-f]{4,6})/i) do |m|\n+        [m[2..-1].to_i(16)].pack('U')\n       end\n     end\n \n     # Replace special characters such as line feed and tabs.\n     def self.decode_special_char(str)\n-      str.gsub(/\\\\0/, \"\\0\")\n-        .gsub(/\\\\t/, \"\\t\")\n-        .gsub(/\\\\b/, \"\\b\")\n-        .gsub(/\\\\f/, \"\\f\")\n-        .gsub(/\\\\n/, \"\\n\")\n-        .gsub(/\\\\\\\"/, '\"')\n-        .gsub(/\\\\r/, \"\\r\")\n+      str.gsub(/\\\\+(\\\"|.)/) do |m|\n+        backslashes = \"\\\\\" * ((m.size - 1) / 2)\n+\n+        if m.size.even?\n+          sequence = m[-2..-1]\n+          sc = special_chars[sequence]\n+\n+          fail EscapeSequenceReserved.new(sequence) unless sc\n+\n+          backslashes + sc\n+        else\n+          backslashes + m[-1]\n+        end\n+      end\n     end\n \n     def self.transform_escaped_chars(str)\n-      str = decode_special_char(str)\n       str = decode_unicode(str)\n-      str.gsub(/\\\\\\\\/, '\\\\').encode('utf-8')\n+      str = decode_special_char(str)\n+      str.encode('utf-8')","path":"lib/toml/string.rb","position":41,"original_position":41,"commit_id":"9b39643cd981584346425bf5b0b151edb2a66e52","original_commit_id":"9b39643cd981584346425bf5b0b151edb2a66e52","user":{"login":"rsim","id":4736,"avatar_url":"https://avatars.githubusercontent.com/u/4736?v=3","gravatar_id":"","url":"https://api.github.com/users/rsim","html_url":"https://github.com/rsim","followers_url":"https://api.github.com/users/rsim/followers","following_url":"https://api.github.com/users/rsim/following{/other_user}","gists_url":"https://api.github.com/users/rsim/gists{/gist_id}","starred_url":"https://api.github.com/users/rsim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsim/subscriptions","organizations_url":"https://api.github.com/users/rsim/orgs","repos_url":"https://api.github.com/users/rsim/repos","events_url":"https://api.github.com/users/rsim/events{/privacy}","received_events_url":"https://api.github.com/users/rsim/received_events","type":"User","site_admin":false},"body":"Why is `encode('utf-8')` necessary here? If needed then probably inside decode_special_char if Unicode sequence is decoded. And then probably better `force_encoding('UTF-8')` so that the encoding of the same string is changed to UTF-8 instead of creating a new string with UTF-8 encoding. See example:\r\n\r\n```ruby\r\n>> str = \"abc\"\r\n=> \"abc\"\r\n>> str.object_id\r\n=> 4224046\r\n>> str.encode('UTF-8').object_id\r\n=> 4224048\r\n>> str.force_encoding('UTF-8').object_id\r\n=> 4224046\r\n```","created_at":"2016-02-23T10:15:06Z","updated_at":"2016-02-23T10:15:06Z","html_url":"https://github.com/emancu/toml-rb/pull/83#discussion_r53760268","pull_request_url":"https://api.github.com/repos/emancu/toml-rb/pulls/83","_links":{"self":{"href":"https://api.github.com/repos/emancu/toml-rb/pulls/comments/53760268"},"html":{"href":"https://github.com/emancu/toml-rb/pull/83#discussion_r53760268"},"pull_request":{"href":"https://api.github.com/repos/emancu/toml-rb/pulls/83"}}},"pull_request":{"url":"https://api.github.com/repos/emancu/toml-rb/pulls/83","id":60290293,"html_url":"https://github.com/emancu/toml-rb/pull/83","diff_url":"https://github.com/emancu/toml-rb/pull/83.diff","patch_url":"https://github.com/emancu/toml-rb/pull/83.patch","issue_url":"https://api.github.com/repos/emancu/toml-rb/issues/83","number":83,"state":"open","locked":false,"title":"Invalid parsing scaped sequences","user":{"login":"emancu","id":56375,"avatar_url":"https://avatars.githubusercontent.com/u/56375?v=3","gravatar_id":"","url":"https://api.github.com/users/emancu","html_url":"https://github.com/emancu","followers_url":"https://api.github.com/users/emancu/followers","following_url":"https://api.github.com/users/emancu/following{/other_user}","gists_url":"https://api.github.com/users/emancu/gists{/gist_id}","starred_url":"https://api.github.com/users/emancu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emancu/subscriptions","organizations_url":"https://api.github.com/users/emancu/orgs","repos_url":"https://api.github.com/users/emancu/repos","events_url":"https://api.github.com/users/emancu/events{/privacy}","received_events_url":"https://api.github.com/users/emancu/received_events","type":"User","site_admin":false},"body":"Closes #78 ","created_at":"2016-02-23T05:31:43Z","updated_at":"2016-02-23T10:15:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5b01b8b24630e4b286d78c44e878a248c80fbab5","assignee":{"login":"emancu","id":56375,"avatar_url":"https://avatars.githubusercontent.com/u/56375?v=3","gravatar_id":"","url":"https://api.github.com/users/emancu","html_url":"https://github.com/emancu","followers_url":"https://api.github.com/users/emancu/followers","following_url":"https://api.github.com/users/emancu/following{/other_user}","gists_url":"https://api.github.com/users/emancu/gists{/gist_id}","starred_url":"https://api.github.com/users/emancu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emancu/subscriptions","organizations_url":"https://api.github.com/users/emancu/orgs","repos_url":"https://api.github.com/users/emancu/repos","events_url":"https://api.github.com/users/emancu/events{/privacy}","received_events_url":"https://api.github.com/users/emancu/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/emancu/toml-rb/pulls/83/commits","review_comments_url":"https://api.github.com/repos/emancu/toml-rb/pulls/83/comments","review_comment_url":"https://api.github.com/repos/emancu/toml-rb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/emancu/toml-rb/issues/83/comments","statuses_url":"https://api.github.com/repos/emancu/toml-rb/statuses/9b39643cd981584346425bf5b0b151edb2a66e52","head":{"label":"emancu:78-invalid_parsing_scaped_sequences","ref":"78-invalid_parsing_scaped_sequences","sha":"9b39643cd981584346425bf5b0b151edb2a66e52","user":{"login":"emancu","id":56375,"avatar_url":"https://avatars.githubusercontent.com/u/56375?v=3","gravatar_id":"","url":"https://api.github.com/users/emancu","html_url":"https://github.com/emancu","followers_url":"https://api.github.com/users/emancu/followers","following_url":"https://api.github.com/users/emancu/following{/other_user}","gists_url":"https://api.github.com/users/emancu/gists{/gist_id}","starred_url":"https://api.github.com/users/emancu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emancu/subscriptions","organizations_url":"https://api.github.com/users/emancu/orgs","repos_url":"https://api.github.com/users/emancu/repos","events_url":"https://api.github.com/users/emancu/events{/privacy}","received_events_url":"https://api.github.com/users/emancu/received_events","type":"User","site_admin":false},"repo":{"id":8393378,"name":"toml-rb","full_name":"emancu/toml-rb","owner":{"login":"emancu","id":56375,"avatar_url":"https://avatars.githubusercontent.com/u/56375?v=3","gravatar_id":"","url":"https://api.github.com/users/emancu","html_url":"https://github.com/emancu","followers_url":"https://api.github.com/users/emancu/followers","following_url":"https://api.github.com/users/emancu/following{/other_user}","gists_url":"https://api.github.com/users/emancu/gists{/gist_id}","starred_url":"https://api.github.com/users/emancu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emancu/subscriptions","organizations_url":"https://api.github.com/users/emancu/orgs","repos_url":"https://api.github.com/users/emancu/repos","events_url":"https://api.github.com/users/emancu/events{/privacy}","received_events_url":"https://api.github.com/users/emancu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/emancu/toml-rb","description":"A parser for TOML using Citrus library.","fork":false,"url":"https://api.github.com/repos/emancu/toml-rb","forks_url":"https://api.github.com/repos/emancu/toml-rb/forks","keys_url":"https://api.github.com/repos/emancu/toml-rb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/emancu/toml-rb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/emancu/toml-rb/teams","hooks_url":"https://api.github.com/repos/emancu/toml-rb/hooks","issue_events_url":"https://api.github.com/repos/emancu/toml-rb/issues/events{/number}","events_url":"https://api.github.com/repos/emancu/toml-rb/events","assignees_url":"https://api.github.com/repos/emancu/toml-rb/assignees{/user}","branches_url":"https://api.github.com/repos/emancu/toml-rb/branches{/branch}","tags_url":"https://api.github.com/repos/emancu/toml-rb/tags","blobs_url":"https://api.github.com/repos/emancu/toml-rb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/emancu/toml-rb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/emancu/toml-rb/git/refs{/sha}","trees_url":"https://api.github.com/repos/emancu/toml-rb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/emancu/toml-rb/statuses/{sha}","languages_url":"https://api.github.com/repos/emancu/toml-rb/languages","stargazers_url":"https://api.github.com/repos/emancu/toml-rb/stargazers","contributors_url":"https://api.github.com/repos/emancu/toml-rb/contributors","subscribers_url":"https://api.github.com/repos/emancu/toml-rb/subscribers","subscription_url":"https://api.github.com/repos/emancu/toml-rb/subscription","commits_url":"https://api.github.com/repos/emancu/toml-rb/commits{/sha}","git_commits_url":"https://api.github.com/repos/emancu/toml-rb/git/commits{/sha}","comments_url":"https://api.github.com/repos/emancu/toml-rb/comments{/number}","issue_comment_url":"https://api.github.com/repos/emancu/toml-rb/issues/comments{/number}","contents_url":"https://api.github.com/repos/emancu/toml-rb/contents/{+path}","compare_url":"https://api.github.com/repos/emancu/toml-rb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/emancu/toml-rb/merges","archive_url":"https://api.github.com/repos/emancu/toml-rb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/emancu/toml-rb/downloads","issues_url":"https://api.github.com/repos/emancu/toml-rb/issues{/number}","pulls_url":"https://api.github.com/repos/emancu/toml-rb/pulls{/number}","milestones_url":"https://api.github.com/repos/emancu/toml-rb/milestones{/number}","notifications_url":"https://api.github.com/repos/emancu/toml-rb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/emancu/toml-rb/labels{/name}","releases_url":"https://api.github.com/repos/emancu/toml-rb/releases{/id}","deployments_url":"https://api.github.com/repos/emancu/toml-rb/deployments","created_at":"2013-02-24T16:56:27Z","updated_at":"2016-02-03T14:38:43Z","pushed_at":"2016-02-23T05:31:43Z","git_url":"git://github.com/emancu/toml-rb.git","ssh_url":"git@github.com:emancu/toml-rb.git","clone_url":"https://github.com/emancu/toml-rb.git","svn_url":"https://github.com/emancu/toml-rb","homepage":null,"size":180,"stargazers_count":34,"watchers_count":34,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":4,"forks":11,"open_issues":4,"watchers":34,"default_branch":"master"}},"base":{"label":"emancu:master","ref":"master","sha":"8de3222c4596993489d153404ad8bda2660865c0","user":{"login":"emancu","id":56375,"avatar_url":"https://avatars.githubusercontent.com/u/56375?v=3","gravatar_id":"","url":"https://api.github.com/users/emancu","html_url":"https://github.com/emancu","followers_url":"https://api.github.com/users/emancu/followers","following_url":"https://api.github.com/users/emancu/following{/other_user}","gists_url":"https://api.github.com/users/emancu/gists{/gist_id}","starred_url":"https://api.github.com/users/emancu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emancu/subscriptions","organizations_url":"https://api.github.com/users/emancu/orgs","repos_url":"https://api.github.com/users/emancu/repos","events_url":"https://api.github.com/users/emancu/events{/privacy}","received_events_url":"https://api.github.com/users/emancu/received_events","type":"User","site_admin":false},"repo":{"id":8393378,"name":"toml-rb","full_name":"emancu/toml-rb","owner":{"login":"emancu","id":56375,"avatar_url":"https://avatars.githubusercontent.com/u/56375?v=3","gravatar_id":"","url":"https://api.github.com/users/emancu","html_url":"https://github.com/emancu","followers_url":"https://api.github.com/users/emancu/followers","following_url":"https://api.github.com/users/emancu/following{/other_user}","gists_url":"https://api.github.com/users/emancu/gists{/gist_id}","starred_url":"https://api.github.com/users/emancu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emancu/subscriptions","organizations_url":"https://api.github.com/users/emancu/orgs","repos_url":"https://api.github.com/users/emancu/repos","events_url":"https://api.github.com/users/emancu/events{/privacy}","received_events_url":"https://api.github.com/users/emancu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/emancu/toml-rb","description":"A parser for TOML using Citrus library.","fork":false,"url":"https://api.github.com/repos/emancu/toml-rb","forks_url":"https://api.github.com/repos/emancu/toml-rb/forks","keys_url":"https://api.github.com/repos/emancu/toml-rb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/emancu/toml-rb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/emancu/toml-rb/teams","hooks_url":"https://api.github.com/repos/emancu/toml-rb/hooks","issue_events_url":"https://api.github.com/repos/emancu/toml-rb/issues/events{/number}","events_url":"https://api.github.com/repos/emancu/toml-rb/events","assignees_url":"https://api.github.com/repos/emancu/toml-rb/assignees{/user}","branches_url":"https://api.github.com/repos/emancu/toml-rb/branches{/branch}","tags_url":"https://api.github.com/repos/emancu/toml-rb/tags","blobs_url":"https://api.github.com/repos/emancu/toml-rb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/emancu/toml-rb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/emancu/toml-rb/git/refs{/sha}","trees_url":"https://api.github.com/repos/emancu/toml-rb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/emancu/toml-rb/statuses/{sha}","languages_url":"https://api.github.com/repos/emancu/toml-rb/languages","stargazers_url":"https://api.github.com/repos/emancu/toml-rb/stargazers","contributors_url":"https://api.github.com/repos/emancu/toml-rb/contributors","subscribers_url":"https://api.github.com/repos/emancu/toml-rb/subscribers","subscription_url":"https://api.github.com/repos/emancu/toml-rb/subscription","commits_url":"https://api.github.com/repos/emancu/toml-rb/commits{/sha}","git_commits_url":"https://api.github.com/repos/emancu/toml-rb/git/commits{/sha}","comments_url":"https://api.github.com/repos/emancu/toml-rb/comments{/number}","issue_comment_url":"https://api.github.com/repos/emancu/toml-rb/issues/comments{/number}","contents_url":"https://api.github.com/repos/emancu/toml-rb/contents/{+path}","compare_url":"https://api.github.com/repos/emancu/toml-rb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/emancu/toml-rb/merges","archive_url":"https://api.github.com/repos/emancu/toml-rb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/emancu/toml-rb/downloads","issues_url":"https://api.github.com/repos/emancu/toml-rb/issues{/number}","pulls_url":"https://api.github.com/repos/emancu/toml-rb/pulls{/number}","milestones_url":"https://api.github.com/repos/emancu/toml-rb/milestones{/number}","notifications_url":"https://api.github.com/repos/emancu/toml-rb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/emancu/toml-rb/labels{/name}","releases_url":"https://api.github.com/repos/emancu/toml-rb/releases{/id}","deployments_url":"https://api.github.com/repos/emancu/toml-rb/deployments","created_at":"2013-02-24T16:56:27Z","updated_at":"2016-02-03T14:38:43Z","pushed_at":"2016-02-23T05:31:43Z","git_url":"git://github.com/emancu/toml-rb.git","ssh_url":"git@github.com:emancu/toml-rb.git","clone_url":"https://github.com/emancu/toml-rb.git","svn_url":"https://github.com/emancu/toml-rb","homepage":null,"size":180,"stargazers_count":34,"watchers_count":34,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":4,"forks":11,"open_issues":4,"watchers":34,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/emancu/toml-rb/pulls/83"},"html":{"href":"https://github.com/emancu/toml-rb/pull/83"},"issue":{"href":"https://api.github.com/repos/emancu/toml-rb/issues/83"},"comments":{"href":"https://api.github.com/repos/emancu/toml-rb/issues/83/comments"},"review_comments":{"href":"https://api.github.com/repos/emancu/toml-rb/pulls/83/comments"},"review_comment":{"href":"https://api.github.com/repos/emancu/toml-rb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/emancu/toml-rb/pulls/83/commits"},"statuses":{"href":"https://api.github.com/repos/emancu/toml-rb/statuses/9b39643cd981584346425bf5b0b151edb2a66e52"}}}}