#6167: $javascript->Object() fails on creating JSON for already scaped strings --------------------------+------------------------------------------------- Reporter: MoNKi | Type: Bug Status: new | Priority: Medium Milestone: 1.2.x.x | Component: Helpers Version: 1.2 Final | Severity: Normal Keywords: | Php_version: n/a Cake_version: | --------------------------+------------------------------------------------- If you have an already scaped string in an array and you try to create a JSON object with javascript->Object(), the returned JSON string is bad formed due to error in javascript->escapeString.
Example: {{{ $var = array('test' => 'my \\"string\\"'); echo '({"test_array":' . $javascript->Object($var) . '})'; }}} Results in: {{{ ({"test_array":{"test":"my \\"string\\""}}) }}} As you can see, de double backslashes makes de first " in the string the end character. Fix (javascript.php), escape also backslashes: {{{ function escapeString($string) { $escape = array("\\" => "\\\\", "\r\n" => '\n', "\r" => '\n', "\n" => '\n', '"' => '\"', "'" => "\\'"); return r(array_keys($escape), array_values($escape), $string); } }}} Now the result is ok: {{{ ({"test_array":{"test":"my \\\"string\\\""}}) }}} I'm on 1.1, but the bug are in 1.2 too if I'm not mistaken. -- Ticket URL: <https://trac.cakephp.org/ticket/6167> CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/> Cake is a rapid development framework for PHP which uses commonly known design patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "tickets cakephp" group. To post to this group, send email to tickets-cakephp@googlegroups.com To unsubscribe from this group, send email to tickets-cakephp+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/tickets-cakephp?hl=en -~----------~----~----~----~------~----~------~--~---