From 92efec6e1e23512e37bab2a6a3e0f979324f1e11 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sat, 9 Jan 2010 23:36:55 +0000 Subject: #479368 by Heine and asimmonds: Fixed drupal_to_js() provides bad unicode conversions. --- modules/simpletest/tests/common.test | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'modules/simpletest/tests/common.test') diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 156bb8fd8..6c617edf7 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -1802,6 +1802,7 @@ class DrupalJSONTest extends DrupalUnitTestCase { } // Characters that must be escaped. $html_unsafe = array('<', '>', '&'); + $html_unsafe_escaped = array('\u003c', '\u003e', '\u0026'); // Verify there aren't character encoding problems with the source string. $this->assertIdentical(strlen($str), 128, t('A string with the full ASCII table has the correct length.')); @@ -1824,6 +1825,10 @@ class DrupalJSONTest extends DrupalUnitTestCase { foreach ($html_unsafe as $char) { $this->assertTrue(strpos($json, $char) === FALSE, t('A JSON encoded string does not contain @s.', array('@s' => $char))); } + // Verify that JSON encoding escapes the HTML unsafe characters + foreach ($html_unsafe_escaped as $char) { + $this->assertTrue(strpos($json, $char) > 0, t('A JSON encoded string contains @s.', array('@s' => $char))); + } $json_decoded = drupal_json_decode($json); $this->assertNotIdentical($source, $json, t('An array encoded in JSON is not identical to the source.')); $this->assertIdentical($source, $json_decoded, t('Encoding structured data to JSON and decoding back results in the original data.')); -- cgit v1.2.3