HTML_Javascript_Convert::escapeString
| From: | culley harrelson | Date: | Sun, 17 Nov 2002 01:01:57 +0000 |
| Subject: | HTML_Javascript_Convert::escapeString | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-10875@lists.php.net to get a copy of this message | ||
HTML_Javascript_Convert::escapeString can't handle the literal new lines
in the script:
<?php
require_once 'HTML/Javascript.php';
require_once 'HTML/Javascript/Convert.php';
$test[0] = "
\"don't\"
\slash
";
$test[1] = "don't";
$js = new HTML_Javascript();
echo $js->startScript();
echo HTML_Javascript_Convert::convertArray($test, 'arTest', true );
echo "alert(arTest[0]);\n";
echo "alert(arTest[1]);\n";
echo $js->endScript();
?>
Here is a patch:
$ diff original.php Convert.php
52c52,54
< return addslashes($str);
---
> $lines = explode("\n", $str);
> $lines = array_map('addslashes', $lines);
> return implode('\n', $lines);