{"action":"created","comment":{"url":"https://api.github.com/repos/phpbench/phpbench/pulls/comments/61296292","id":61296292,"diff_hunk":"@@ -47,28 +47,114 @@ public function decode($jsonString)\n     }\n \n     /**\n-     * Taken from: https://gist.github.com/larruda/967110d74d98c1cd4ee1.\n+     * Allow \"non-strict\" JSON - i.e. if no quotes are provided then try and\n+     * add them.\n      */\n     private function normalize($jsonString)\n     {\n         if (!is_string($jsonString)) {\n             throw new \\InvalidArgumentException(sprintf(\n-                'Expected a string, got a \"%s\"',\n-                is_object($jsonString) ? get_class($jsonString) : gettype($jsonString)\n+                'Expected a string, got \"%s\"',\n+                gettype($jsonString)\n             ));\n         }\n+        $chars = str_split($jsonString);\n+        $inRight = $inQuote = $inFakeQuote = false;\n+        $fakeQuoteStart = null;\n \n-        if (substr($jsonString, 0, 1) !== '{') {\n-            $jsonString = '{' . $jsonString;\n-            $jsonString = $jsonString . '}';\n+        if (empty($chars)) {\n+            return;\n         }\n \n-        $jsonString = preg_replace(\n-            '{(\\s*?\\{\\s*?|\\s*?,\\s*?)([\\'\"])?([\\$\\.a-zA-Z0-9\\[\\]\\_]+)([\\'\"])?:}',\n-            '\\1\"\\3\":',\n-            $jsonString\n-        );\n+        if ($chars[0] !== '{') {\n+            array_unshift($chars, '{');\n+        }\n+\n+        for ($index = 0; $index < count($chars); $index++) {\n+            $char = $chars[$index];\n+            $prevChar = isset($chars[$index - 1]) ? $chars[$index - 1] : null;\n+\n+            if (!$inQuote && $prevChar == ':') {\n+                $inRight = true;\n+            }\n+\n+            if (!$inQuote && preg_match('{\\{,}', $char)) {\n+                $inRight = false;\n+            }\n+\n+            // detect start of unquoted string\n+            if (!$inQuote && preg_match('{[\\$a-zA-Z0-9]}', $char)) {\n+                array_splice($chars, $index, 0, '\"');\n+                $fakeQuoteStart = $index;\n+                $index++;\n+                $inQuote = $inFakeQuote = true;\n+                continue;\n+            }\n+\n+            // if we added a \"fake\" quote, look for the end of the unquoted string\n+            if ($inFakeQuote && preg_match('{[\\s:\\}\\],]}', $char)) {\n+                // if we are on the left side, then \"]\" is OK.\n+                if (!$inRight && $char === ']') {\n+                    continue;\n+                }\n+\n+                if ($inRight) {\n+\n+                    // extract the right hand value\n+                    $string = implode('', array_slice($chars, $fakeQuoteStart + 1, $index - 1 - $fakeQuoteStart));\n+\n+                    // if it is a number, then we don't quote it\n+                    if (is_numeric($string)) {\n+                        unset($chars[$fakeQuoteStart]);\n+                        $chars = array_values($chars);\n+                        $inQuote = $inFakeQuote = false;\n+                        $index--;\n+                        continue;\n+                    }\n+\n+                    // if it is a boolean, then we don't quote it\n+                    if (in_array($string, ['true', 'false'])) {\n+                        unset($chars[$fakeQuoteStart]);\n+                        $chars = array_values($chars);\n+                        $inQuote = $inFakeQuote = false;\n+                        $index--;\n+                        continue;\n+                    }\n+                }\n+\n+                // add the ending quote\n+                array_splice($chars, $index, 0, '\"');\n+                $index++;\n+                $inQuote = $inFakeQuote = false;\n+                continue;\n+            }\n+\n+            // enter standard quote mode\n+            if (!$inQuote && $char === '\"') {\n+                $inQuote = true;\n+                continue;\n+            }\n+\n+            // if we are in quote mode and encounter a closing quote, and the last character\n+            // was not the escape character\n+            if ($inQuote && $char === '\"' && $prevChar !== '\\\\') {\n+                $inQuote = $inFakeQuote = false;\n+                continue;\n+            }\n+        }\n+\n+        // if we were in a fake quote and hit the end, then add the closing quote\n+        if ($inFakeQuote) {\n+            $chars[] = '\"';\n+        }\n+\n+        $normalized = implode('', $chars);\n+\n+        // if we added a bracket at the begining, then add one to the end if required\n+        if (substr_count($normalized, '{') == substr_count($normalized, '}') + 1) {","path":"lib/Json/JsonDecoder.php","position":119,"original_position":119,"commit_id":"ca1a4ad64505f785c33279db41e02b8301e0fc98","original_commit_id":"ca1a4ad64505f785c33279db41e02b8301e0fc98","user":{"login":"dantleech","id":530801,"avatar_url":"https://avatars.githubusercontent.com/u/530801?v=3","gravatar_id":"","url":"https://api.github.com/users/dantleech","html_url":"https://github.com/dantleech","followers_url":"https://api.github.com/users/dantleech/followers","following_url":"https://api.github.com/users/dantleech/following{/other_user}","gists_url":"https://api.github.com/users/dantleech/gists{/gist_id}","starred_url":"https://api.github.com/users/dantleech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dantleech/subscriptions","organizations_url":"https://api.github.com/users/dantleech/orgs","repos_url":"https://api.github.com/users/dantleech/repos","events_url":"https://api.github.com/users/dantleech/events{/privacy}","received_events_url":"https://api.github.com/users/dantleech/received_events","type":"User","site_admin":false},"body":"thats not going to work for quoted `{` characters","created_at":"2016-04-27T17:01:30Z","updated_at":"2016-04-27T17:01:30Z","html_url":"https://github.com/phpbench/phpbench/pull/394#discussion_r61296292","pull_request_url":"https://api.github.com/repos/phpbench/phpbench/pulls/394","_links":{"self":{"href":"https://api.github.com/repos/phpbench/phpbench/pulls/comments/61296292"},"html":{"href":"https://github.com/phpbench/phpbench/pull/394#discussion_r61296292"},"pull_request":{"href":"https://api.github.com/repos/phpbench/phpbench/pulls/394"}}},"pull_request":{"url":"https://api.github.com/repos/phpbench/phpbench/pulls/394","id":68067715,"html_url":"https://github.com/phpbench/phpbench/pull/394","diff_url":"https://github.com/phpbench/phpbench/pull/394.diff","patch_url":"https://github.com/phpbench/phpbench/pull/394.patch","issue_url":"https://api.github.com/repos/phpbench/phpbench/issues/394","number":394,"state":"open","locked":false,"title":"Non-strict JSON parser","user":{"login":"dantleech","id":530801,"avatar_url":"https://avatars.githubusercontent.com/u/530801?v=3","gravatar_id":"","url":"https://api.github.com/users/dantleech","html_url":"https://github.com/dantleech","followers_url":"https://api.github.com/users/dantleech/followers","following_url":"https://api.github.com/users/dantleech/following{/other_user}","gists_url":"https://api.github.com/users/dantleech/gists{/gist_id}","starred_url":"https://api.github.com/users/dantleech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dantleech/subscriptions","organizations_url":"https://api.github.com/users/dantleech/orgs","repos_url":"https://api.github.com/users/dantleech/repos","events_url":"https://api.github.com/users/dantleech/events{/privacy}","received_events_url":"https://api.github.com/users/dantleech/received_events","type":"User","site_admin":false},"body":"Introduces a JSON normalizer for \"non-strict\" JSON, replacing the original and flawed `preg_replace`.\r\n\r\nFixes #383","created_at":"2016-04-27T14:56:28Z","updated_at":"2016-04-27T17:01:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cc19952f3b2c642354758662fa93c277610e59f9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/phpbench/phpbench/pulls/394/commits","review_comments_url":"https://api.github.com/repos/phpbench/phpbench/pulls/394/comments","review_comment_url":"https://api.github.com/repos/phpbench/phpbench/pulls/comments{/number}","comments_url":"https://api.github.com/repos/phpbench/phpbench/issues/394/comments","statuses_url":"https://api.github.com/repos/phpbench/phpbench/statuses/ca1a4ad64505f785c33279db41e02b8301e0fc98","head":{"label":"phpbench:json_parser_quotes","ref":"json_parser_quotes","sha":"ca1a4ad64505f785c33279db41e02b8301e0fc98","user":{"login":"phpbench","id":12785153,"avatar_url":"https://avatars.githubusercontent.com/u/12785153?v=3","gravatar_id":"","url":"https://api.github.com/users/phpbench","html_url":"https://github.com/phpbench","followers_url":"https://api.github.com/users/phpbench/followers","following_url":"https://api.github.com/users/phpbench/following{/other_user}","gists_url":"https://api.github.com/users/phpbench/gists{/gist_id}","starred_url":"https://api.github.com/users/phpbench/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phpbench/subscriptions","organizations_url":"https://api.github.com/users/phpbench/orgs","repos_url":"https://api.github.com/users/phpbench/repos","events_url":"https://api.github.com/users/phpbench/events{/privacy}","received_events_url":"https://api.github.com/users/phpbench/received_events","type":"Organization","site_admin":false},"repo":{"id":34982189,"name":"phpbench","full_name":"phpbench/phpbench","owner":{"login":"phpbench","id":12785153,"avatar_url":"https://avatars.githubusercontent.com/u/12785153?v=3","gravatar_id":"","url":"https://api.github.com/users/phpbench","html_url":"https://github.com/phpbench","followers_url":"https://api.github.com/users/phpbench/followers","following_url":"https://api.github.com/users/phpbench/following{/other_user}","gists_url":"https://api.github.com/users/phpbench/gists{/gist_id}","starred_url":"https://api.github.com/users/phpbench/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phpbench/subscriptions","organizations_url":"https://api.github.com/users/phpbench/orgs","repos_url":"https://api.github.com/users/phpbench/repos","events_url":"https://api.github.com/users/phpbench/events{/privacy}","received_events_url":"https://api.github.com/users/phpbench/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/phpbench/phpbench","description":"PHP Benchmarking framework","fork":false,"url":"https://api.github.com/repos/phpbench/phpbench","forks_url":"https://api.github.com/repos/phpbench/phpbench/forks","keys_url":"https://api.github.com/repos/phpbench/phpbench/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phpbench/phpbench/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phpbench/phpbench/teams","hooks_url":"https://api.github.com/repos/phpbench/phpbench/hooks","issue_events_url":"https://api.github.com/repos/phpbench/phpbench/issues/events{/number}","events_url":"https://api.github.com/repos/phpbench/phpbench/events","assignees_url":"https://api.github.com/repos/phpbench/phpbench/assignees{/user}","branches_url":"https://api.github.com/repos/phpbench/phpbench/branches{/branch}","tags_url":"https://api.github.com/repos/phpbench/phpbench/tags","blobs_url":"https://api.github.com/repos/phpbench/phpbench/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phpbench/phpbench/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phpbench/phpbench/git/refs{/sha}","trees_url":"https://api.github.com/repos/phpbench/phpbench/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phpbench/phpbench/statuses/{sha}","languages_url":"https://api.github.com/repos/phpbench/phpbench/languages","stargazers_url":"https://api.github.com/repos/phpbench/phpbench/stargazers","contributors_url":"https://api.github.com/repos/phpbench/phpbench/contributors","subscribers_url":"https://api.github.com/repos/phpbench/phpbench/subscribers","subscription_url":"https://api.github.com/repos/phpbench/phpbench/subscription","commits_url":"https://api.github.com/repos/phpbench/phpbench/commits{/sha}","git_commits_url":"https://api.github.com/repos/phpbench/phpbench/git/commits{/sha}","comments_url":"https://api.github.com/repos/phpbench/phpbench/comments{/number}","issue_comment_url":"https://api.github.com/repos/phpbench/phpbench/issues/comments{/number}","contents_url":"https://api.github.com/repos/phpbench/phpbench/contents/{+path}","compare_url":"https://api.github.com/repos/phpbench/phpbench/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phpbench/phpbench/merges","archive_url":"https://api.github.com/repos/phpbench/phpbench/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phpbench/phpbench/downloads","issues_url":"https://api.github.com/repos/phpbench/phpbench/issues{/number}","pulls_url":"https://api.github.com/repos/phpbench/phpbench/pulls{/number}","milestones_url":"https://api.github.com/repos/phpbench/phpbench/milestones{/number}","notifications_url":"https://api.github.com/repos/phpbench/phpbench/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phpbench/phpbench/labels{/name}","releases_url":"https://api.github.com/repos/phpbench/phpbench/releases{/id}","deployments_url":"https://api.github.com/repos/phpbench/phpbench/deployments","created_at":"2015-05-03T10:34:08Z","updated_at":"2016-04-25T10:07:40Z","pushed_at":"2016-04-27T16:57:52Z","git_url":"git://github.com/phpbench/phpbench.git","ssh_url":"git@github.com:phpbench/phpbench.git","clone_url":"https://github.com/phpbench/phpbench.git","svn_url":"https://github.com/phpbench/phpbench","homepage":null,"size":5791,"stargazers_count":318,"watchers_count":318,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":13,"mirror_url":null,"open_issues_count":35,"forks":13,"open_issues":35,"watchers":318,"default_branch":"master"}},"base":{"label":"phpbench:master","ref":"master","sha":"1201bc0c10f5c44986989dc6ad613cb545616d96","user":{"login":"phpbench","id":12785153,"avatar_url":"https://avatars.githubusercontent.com/u/12785153?v=3","gravatar_id":"","url":"https://api.github.com/users/phpbench","html_url":"https://github.com/phpbench","followers_url":"https://api.github.com/users/phpbench/followers","following_url":"https://api.github.com/users/phpbench/following{/other_user}","gists_url":"https://api.github.com/users/phpbench/gists{/gist_id}","starred_url":"https://api.github.com/users/phpbench/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phpbench/subscriptions","organizations_url":"https://api.github.com/users/phpbench/orgs","repos_url":"https://api.github.com/users/phpbench/repos","events_url":"https://api.github.com/users/phpbench/events{/privacy}","received_events_url":"https://api.github.com/users/phpbench/received_events","type":"Organization","site_admin":false},"repo":{"id":34982189,"name":"phpbench","full_name":"phpbench/phpbench","owner":{"login":"phpbench","id":12785153,"avatar_url":"https://avatars.githubusercontent.com/u/12785153?v=3","gravatar_id":"","url":"https://api.github.com/users/phpbench","html_url":"https://github.com/phpbench","followers_url":"https://api.github.com/users/phpbench/followers","following_url":"https://api.github.com/users/phpbench/following{/other_user}","gists_url":"https://api.github.com/users/phpbench/gists{/gist_id}","starred_url":"https://api.github.com/users/phpbench/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phpbench/subscriptions","organizations_url":"https://api.github.com/users/phpbench/orgs","repos_url":"https://api.github.com/users/phpbench/repos","events_url":"https://api.github.com/users/phpbench/events{/privacy}","received_events_url":"https://api.github.com/users/phpbench/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/phpbench/phpbench","description":"PHP Benchmarking framework","fork":false,"url":"https://api.github.com/repos/phpbench/phpbench","forks_url":"https://api.github.com/repos/phpbench/phpbench/forks","keys_url":"https://api.github.com/repos/phpbench/phpbench/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phpbench/phpbench/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phpbench/phpbench/teams","hooks_url":"https://api.github.com/repos/phpbench/phpbench/hooks","issue_events_url":"https://api.github.com/repos/phpbench/phpbench/issues/events{/number}","events_url":"https://api.github.com/repos/phpbench/phpbench/events","assignees_url":"https://api.github.com/repos/phpbench/phpbench/assignees{/user}","branches_url":"https://api.github.com/repos/phpbench/phpbench/branches{/branch}","tags_url":"https://api.github.com/repos/phpbench/phpbench/tags","blobs_url":"https://api.github.com/repos/phpbench/phpbench/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phpbench/phpbench/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phpbench/phpbench/git/refs{/sha}","trees_url":"https://api.github.com/repos/phpbench/phpbench/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phpbench/phpbench/statuses/{sha}","languages_url":"https://api.github.com/repos/phpbench/phpbench/languages","stargazers_url":"https://api.github.com/repos/phpbench/phpbench/stargazers","contributors_url":"https://api.github.com/repos/phpbench/phpbench/contributors","subscribers_url":"https://api.github.com/repos/phpbench/phpbench/subscribers","subscription_url":"https://api.github.com/repos/phpbench/phpbench/subscription","commits_url":"https://api.github.com/repos/phpbench/phpbench/commits{/sha}","git_commits_url":"https://api.github.com/repos/phpbench/phpbench/git/commits{/sha}","comments_url":"https://api.github.com/repos/phpbench/phpbench/comments{/number}","issue_comment_url":"https://api.github.com/repos/phpbench/phpbench/issues/comments{/number}","contents_url":"https://api.github.com/repos/phpbench/phpbench/contents/{+path}","compare_url":"https://api.github.com/repos/phpbench/phpbench/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phpbench/phpbench/merges","archive_url":"https://api.github.com/repos/phpbench/phpbench/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phpbench/phpbench/downloads","issues_url":"https://api.github.com/repos/phpbench/phpbench/issues{/number}","pulls_url":"https://api.github.com/repos/phpbench/phpbench/pulls{/number}","milestones_url":"https://api.github.com/repos/phpbench/phpbench/milestones{/number}","notifications_url":"https://api.github.com/repos/phpbench/phpbench/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phpbench/phpbench/labels{/name}","releases_url":"https://api.github.com/repos/phpbench/phpbench/releases{/id}","deployments_url":"https://api.github.com/repos/phpbench/phpbench/deployments","created_at":"2015-05-03T10:34:08Z","updated_at":"2016-04-25T10:07:40Z","pushed_at":"2016-04-27T16:57:52Z","git_url":"git://github.com/phpbench/phpbench.git","ssh_url":"git@github.com:phpbench/phpbench.git","clone_url":"https://github.com/phpbench/phpbench.git","svn_url":"https://github.com/phpbench/phpbench","homepage":null,"size":5791,"stargazers_count":318,"watchers_count":318,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":13,"mirror_url":null,"open_issues_count":35,"forks":13,"open_issues":35,"watchers":318,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/phpbench/phpbench/pulls/394"},"html":{"href":"https://github.com/phpbench/phpbench/pull/394"},"issue":{"href":"https://api.github.com/repos/phpbench/phpbench/issues/394"},"comments":{"href":"https://api.github.com/repos/phpbench/phpbench/issues/394/comments"},"review_comments":{"href":"https://api.github.com/repos/phpbench/phpbench/pulls/394/comments"},"review_comment":{"href":"https://api.github.com/repos/phpbench/phpbench/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/phpbench/phpbench/pulls/394/commits"},"statuses":{"href":"https://api.github.com/repos/phpbench/phpbench/statuses/ca1a4ad64505f785c33279db41e02b8301e0fc98"}}}}