Skip to content

Commit

Permalink
Fixing escaping of forward slash for JS Engines.
Browse files Browse the repository at this point in the history
  • Loading branch information
predominant committed Mar 9, 2010
1 parent 382e11c commit 7334fdf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
15 changes: 7 additions & 8 deletions cake/libs/view/helpers/js.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,24 +676,23 @@ function _utf8ToHex($string) {
for ($i = 0; $i < $length; ++$i) {
$ord = ord($string{$i});
switch (true) {
case $ord == 0x08:
case $ord == 0x08: // Backspace
$return .= '\b';
break;
case $ord == 0x09:
case $ord == 0x09: // Tab
$return .= '\t';
break;
case $ord == 0x0A:
case $ord == 0x0A: // New Line
$return .= '\n';
break;
case $ord == 0x0C:
case $ord == 0x0C: // New Page
$return .= '\f';
break;
case $ord == 0x0D:
case $ord == 0x0D: // Carriage Return
$return .= '\r';
break;
case $ord == 0x22:
case $ord == 0x2F:
case $ord == 0x5C:
case $ord == 0x22: // Character: "
case $ord == 0x5C: // Character: \
$return .= '\\' . $string{$i};
break;
case (($ord >= 0x20) && ($ord <= 0x7F)):
Expand Down
12 changes: 6 additions & 6 deletions cake/tests/cases/libs/view/helpers/jquery_engine.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ function testEffect() {
*/
function testRequest() {
$result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1));
$expected = '$.ajax({url:"\\/posts\\/view\\/1"});';
$expected = '$.ajax({url:"/posts/view/1"});';
$this->assertEqual($result, $expected);

$result = $this->Jquery->request(array('controller' => 'posts', 'action' => 'view', 1), array(
'update' => '#content'
));
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {$("#content").html(data);}, url:"\/posts\/view\/1"});';
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {$("#content").html(data);}, url:"/posts/view/1"});';
$this->assertEqual($result, $expected);

$result = $this->Jquery->request('/people/edit/1', array(
Expand All @@ -175,7 +175,7 @@ function testRequest() {
'data' => array('name' => 'jim', 'height' => '185cm'),
'wrapCallbacks' => false
));
$expected = '$.ajax({beforeSend:doBefore, complete:doComplete, data:"name=jim&height=185cm", dataType:"json", error:handleError, success:doSuccess, type:"post", url:"\\/people\\/edit\\/1"});';
$expected = '$.ajax({beforeSend:doBefore, complete:doComplete, data:"name=jim&height=185cm", dataType:"json", error:handleError, success:doSuccess, type:"post", url:"/people/edit/1"});';
$this->assertEqual($result, $expected);

$result = $this->Jquery->request('/people/edit/1', array(
Expand All @@ -184,7 +184,7 @@ function testRequest() {
'method' => 'post',
'wrapCallbacks' => false
));
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$expected = '$.ajax({dataType:"html", success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"/people/edit/1"});';
$this->assertEqual($result, $expected);

$result = $this->Jquery->request('/people/edit/1', array(
Expand All @@ -195,7 +195,7 @@ function testRequest() {
'data' => '$("#someId").serialize()',
'wrapCallbacks' => false
));
$expected = '$.ajax({data:$("#someId").serialize(), dataType:"html", success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$expected = '$.ajax({data:$("#someId").serialize(), dataType:"html", success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"/people/edit/1"});';
$this->assertEqual($result, $expected);

$result = $this->Jquery->request('/people/edit/1', array(
Expand All @@ -205,7 +205,7 @@ function testRequest() {
'dataExpression' => true,
'data' => '$("#someId").serialize()',
));
$expected = '$.ajax({beforeSend:function (XMLHttpRequest) {doBefore}, data:$("#someId").serialize(), success:function (data, textStatus) {doFoo}, type:"post", url:"\\/people\\/edit\\/1"});';
$expected = '$.ajax({beforeSend:function (XMLHttpRequest) {doBefore}, data:$("#someId").serialize(), success:function (data, textStatus) {doFoo}, type:"post", url:"/people/edit/1"});';
$this->assertEqual($result, $expected);
}

Expand Down

0 comments on commit 7334fdf

Please sign in to comment.