Permalink
Browse files

Fixing newline escaping for single quote strings, output now matches …

…json_encode().

Test added, and old test fixed.
Fixing buffering issues, causing test suite menu to disappear when running JavascriptHelper Test case.
Fixes #6167

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8134 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
markstory committed Apr 4, 2009
1 parent 392a6b1 commit d74e2d1a73f36ca777ca0df45d9411242d65f31f
Showing with 14 additions and 1 deletion.
  1. +1 −1 cake/libs/view/helpers/javascript.php
  2. +13 −0 cake/tests/cases/libs/view/helpers/javascript.test.php
@@ -319,7 +319,7 @@ function escapeScript($script) {
* @return string Escaped string.
*/
function escapeString($string) {
- $escape = array("\r\n" => '\n', "\r" => '\n', "\n" => '\n', '"' => '\"', "'" => "\\'");
+ $escape = array('\n' => '\\\n', "\r\n" => '\n', "\r" => '\n', "\n" => '\n', '"' => '\"', "'" => "\\'");
return str_replace(array_keys($escape), array_values($escape), $string);
}
/**
@@ -408,6 +408,7 @@ function testObjectNonNative() {
* @return void
*/
function testScriptBlock() {
+ ob_flush();
$result = $this->Javascript->codeBlock('something', array('allowCache' => true, 'safe' => false));
$this->assertPattern('/^<script[^<>]+>something<\/script>$/', $result);
$this->assertPattern('/^<script[^<>]+type="text\/javascript">something<\/script>$/', $result);
@@ -657,6 +658,18 @@ function testEscapeString() {
$result = $this->Javascript->escapeString('my \\"string\\"');
$expected = 'my \\\"string\\\"';
$this->assertEqual($result, $expected);
+
+ $result = $this->Javascript->escapeString('my string\nanother line');
+ $expected = 'my string\\\nanother line';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Javascript->escapeString('String with \n string that looks like newline');
+ $expected = 'String with \\\n string that looks like newline';
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Javascript->escapeString('String with \n string that looks like newline');
+ $expected = 'String with \\\n string that looks like newline';
+ $this->assertEqual($result, $expected);
}
/**
* testAfterRender method

0 comments on commit d74e2d1

Please sign in to comment.