Skip to content

Commit

Permalink
fix js escape inside html script tag
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSumin committed Jul 31, 2012
1 parent 19139b8 commit 6eb2118
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog
@@ -1,3 +1,5 @@
v 0.3.1
* fix js escape inside html script tag
v 0.3.0
* make package.json
* escape <fest:value> inside <script> with jsEscape by default
Expand Down
4 changes: 4 additions & 0 deletions lib/compile.js
Expand Up @@ -272,6 +272,7 @@ var compile = (function(){
for (var i = 0; i < attrs.expr.length; i++) {
section.source += 'try{__fest_attrs[' + i + ']=__fest_escapeHTML(' + _getExpr(attrs.expr[i], 'expression #' + (i + 1) + ' in attribute "' + attrs.name[i] + '"') + ')}catch(e){__fest_attrs[' + i + ']=""; __fest_log_error(e.message);}';
}
stack.push('html:' + node.name);
stack.push(node.name in short_tags ? 'shorttag' : 'tag');
opentag = true;
section.source += '__fest_pushstr(' + context_name + ',"<' + node.name + attrs.text + '");';
Expand Down Expand Up @@ -335,6 +336,8 @@ var compile = (function(){
}
if (node.__fest_output === 'text'){
section.source += '__fest_pushstr(' + context_name + ',';
} else if(node.__fest_output === 'html' && stack.indexOf('html:script') != -1) {
section.source += '__fest_pushstr(' + context_name + ',__fest_escapeJS(';
} else if(node.__fest_output === 'js') {
section.source += '__fest_pushstr(' + context_name + ',__fest_escapeJS(';
} else {
Expand Down Expand Up @@ -435,6 +438,7 @@ var compile = (function(){
stack.pop();

if (node.ns[node.prefix] != fest_ns){
stack.pop();
if (!(node.name in short_tags)){
section.source += '__fest_pushstr(' + context_name + ',"</' + node.name + '>");';
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "fest",
"description": "JS Templates",
"keywords": ["template", "templating", "html", "xml"],
"version": "0.3.0",
"version": "0.3.1",
"repository": {
"type": "git",
"url": "http://github.com/mailru/fest.git"
Expand Down
2 changes: 1 addition & 1 deletion tests/tests-script.js
Expand Up @@ -11,7 +11,7 @@ vows.describe('Fest tests').addBatch({
return promise;
},
'result':function(result){
assert.equal(result, '"true""true\\""');
assert.equal(result, '"true""true&quot;"');
}
},
'script with syntax errors in file':{
Expand Down

0 comments on commit 6eb2118

Please sign in to comment.