Skip to content
Browse files

note escape string

  • Loading branch information...
1 parent 4be2e59 commit 9a1997d5476902e6d0edcdf8a52c1c92affad226 @yiminghe yiminghe committed Oct 18, 2012
Showing with 8 additions and 42 deletions.
  1. +2 −4 bin/tests/xtemplate/t-tpl.html
  2. +2 −38 bin/tests/xtemplate/t.js
  3. +4 −0 src/xtemplate/sub-modules/compiler/src/compiler.js
View
6 bin/tests/xtemplate/t-tpl.html
@@ -1,7 +1,5 @@
<div>
-
- {{#each titles}}
- {{title}}
- {{/each}}
+ \\
+ {{"'2 \\"+2}}
</div>
View
40 bin/tests/xtemplate/t.js
@@ -17,44 +17,8 @@ KISSY.add("tests/t", function () {
includeCommand = commands["include"],
getProperty = utils["getProperty"],
subTpls = option.subTpls;
- buffer += '<div>\r\n \r\n ';
- var option0 = {
- commands: commands,
- utils: utils,
- cache: cache,
- subTpls: subTpls
- };
- var params1 = [];
- var id2;
- var tmp3 = getProperty("titles", scopes[0]);
- if (tmp3 === false) {
- log("can not find property: 'titles' at line 3", "warn");
- id2 = "";
- } else {
- id2 = tmp3[0];
- }
- params1.push(id2);
- option0.params = params1;
- option0.fn = function (scopes) {
- var buffer = "";
- buffer += '\r\n ';
- var id4;
- var tmp5 = getProperty("title", scopes[0]);
- if (tmp5 === false) {
- log("can not find property: 'title' at line 4", "warn");
- id4 = "";
- } else {
- id4 = tmp5[0];
- }
- buffer += escapeHTML(id4);
- buffer += ' \r\n ';
- return buffer;
- };
- try {
- buffer += eachCommand(scopes, option0);
- } catch (e) {
- error(e.message + ": 'each' at line 3");
- }
+ buffer += '<div>\r\n \\\\\r\n ';
+ buffer += escapeHTML(('\'2 \\') + (2));
buffer += '\r\n \r\n</div>';
return buffer;
};
View
4 src/xtemplate/sub-modules/compiler/src/compiler.js
@@ -296,6 +296,10 @@ KISSY.add("xtemplate/compiler", function (S, parser, ast) {
},
'string': function (e) {
+ // no need to escape \ or \n
+ // it is code in template too,
+ // just escape ' in case user use " for string in template code
+ // but here we use ' for string in template code
return ['', ["'" + e.value.replace(/'/g, "\\'") + "'"]];
},

0 comments on commit 9a1997d

Please sign in to comment.
Something went wrong with that request. Please try again.