From 55ce110126c81c7f7c821183fab3018cacc40016 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 3 May 2012 00:34:24 +0200 Subject: fixed a JSON bug with handling backspaces This was fixed in upstream and the upstream tests caught this :-) --- inc/JSON.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/JSON.php b/inc/JSON.php index 012697eb3..7f89005ff 100644 --- a/inc/JSON.php +++ b/inc/JSON.php @@ -569,17 +569,17 @@ class JSON { } - } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && - in_array($top['what'], array(JSON_SLICE, JSON_IN_ARR, JSON_IN_OBJ))) { + } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != JSON_IN_STR)) { // found a quote, and we are not inside a string array_push($stk, array('what' => JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c})); //print("Found start of string at {$c}\n"); } elseif (($chrs{$c} == $top['delim']) && ($top['what'] == JSON_IN_STR) && - (($chrs{$c - 1} != "\\") || - ($chrs{$c - 1} == "\\" && $chrs{$c - 2} == "\\"))) { + ((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) { // found a quote, we're in a string, and it's not escaped + // we know that it's not escaped becase there is _not_ an + // odd number of backslashes at the end of the string so far array_pop($stk); //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); -- cgit v1.2.3