summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-12-11 00:18:13 -0600
committerwebchick <webchick@24967.no-reply.drupal.org>2011-12-11 00:18:13 -0600
commit6fcc87bf4e930d073c67f676131bba65008a79c5 (patch)
tree9b49f11a84ebc2032d37504beabc157d1e379612 /modules/simpletest/tests
parent11d884bee7d0e00ede4cc0c3c147d787292b9b29 (diff)
downloadbrdo-6fcc87bf4e930d073c67f676131bba65008a79c5.tar.gz
brdo-6fcc87bf4e930d073c67f676131bba65008a79c5.tar.bz2
Issue #479368 by Heine, Roger Saner, xjm, mcarbone, keichee, asimmonds: Fixed Create RFC compliant HTML safe JSON.
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r--modules/simpletest/tests/common.test11
1 files changed, 9 insertions, 2 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index a643ff94f..987efbf3a 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -2341,8 +2341,10 @@ class DrupalJSONTest extends DrupalUnitTestCase {
$str .= chr($i);
}
// Characters that must be escaped.
- $html_unsafe = array('<', '>', '&');
- $html_unsafe_escaped = array('\u003c', '\u003e', '\u0026');
+ // We check for unescaped " separately.
+ $html_unsafe = array('<', '>', '\'', '&');
+ // The following are the encoded forms of: < > ' & "
+ $html_unsafe_escaped = array('\u003C', '\u003E', '\u0027', '\u0026', '\u0022');
// 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.'));
@@ -2354,6 +2356,11 @@ class DrupalJSONTest extends DrupalUnitTestCase {
$json = drupal_json_encode($str);
$this->assertTrue(strlen($json) > strlen($str), t('A JSON encoded string is larger than the source string.'));
+ // The first and last characters should be ", and no others.
+ $this->assertTrue($json[0] == '"', t('A JSON encoded string begins with ".'));
+ $this->assertTrue($json[strlen($json) - 1] == '"', t('A JSON encoded string ends with ".'));
+ $this->assertTrue(substr_count($json, '"') == 2, t('A JSON encoded string contains exactly two ".'));
+
// Verify that encoding/decoding is reversible.
$json_decoded = drupal_json_decode($json);
$this->assertIdentical($str, $json_decoded, t('Encoding a string to JSON and decoding back results in the original string.'));