From 4a5173151d4ee3e923a9f5fba85f2aaa77cf8d34 Mon Sep 17 00:00:00 2001 From: fabien Date: Tue, 20 Oct 2009 04:25:01 +0000 Subject: [PATCH] added a js escaping strategy git-svn-id: http://svn.twig-project.org/trunk@81 93ef8e89-cb99-4229-a87c-7fa0fa45744b --- bin/create_pear_package.php | 3 --- lib/Twig/runtime.php | 26 ++++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bin/create_pear_package.php b/bin/create_pear_package.php index e9ebf6c..0ed7a89 100644 --- a/bin/create_pear_package.php +++ b/bin/create_pear_package.php @@ -1,8 +1,5 @@ getCharset()); + switch ($type) + { + case 'js': + // a function the c-escapes a string, making it suitable to be placed in a JavaScript string + return str_replace(array("\\" , "\n" , "\r" , "\"" , "'"), + array("\\\\", "\\n" , "\\r", "\\\"", "\\'"), + $string); + case 'html': + default: + return htmlspecialchars($string, ENT_QUOTES, $env->getCharset()); + } } // add multibyte extensions if possible -- 1.7.2.5