Skip to content

Commit

Permalink
bugfix for numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
olado committed Nov 30, 2014
1 parent c192514 commit ae234eb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
10 changes: 5 additions & 5 deletions benchmarks/templating/doT.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

doT.encodeHTMLSource = function(doNotSkipEncoded) {
var encodeHTMLRules = { "&": "&#38;", "<": "&#60;", ">": "&#62;", '"': '&#34;', "'": '&#39;', "/": '&#47;' },
matchHTML = doNotSkipEncoded ? /&|<|>|"|'|\//g : /&(?!#?\w+;)|<|>|"|'|\//g;
matchHTML = doNotSkipEncoded ? /[&<>"'\/]/g : /&(?!#?\w+;)|<|>|"|'|\//g;
return function(code) {
return code ? code.replace(matchHTML, function(m) {return encodeHTMLRules[m] || m;}) : "";
};
Expand All @@ -46,8 +46,8 @@
}

var startend = {
append: { start: "'+(''+", end: ")+'", startencode: "'+encodeHTML(" },
split: { start: "';out+=(''+", end: ");out+='", startencode: "';out+=encodeHTML(" }
append: { start: "'+(", end: ")+'", startencode: "'+encodeHTML(" },
split: { start: "';out+=(", end: ");out+='", startencode: "';out+=encodeHTML(" }
}, skip = /$^/;

function resolveDefs(c, block, def) {
Expand Down Expand Up @@ -117,8 +117,8 @@
})
+ "';return out;")
.replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r')
.replace(/(\s|;|\}|^|\{)out\+='';/g, '$1').replace(/\+''/g, '')
.replace(/(\s|;|\}|^|\{)out\+=''\+/g,'$1out+=');
.replace(/(\s|;|\}|^|\{)out\+='';/g, '$1').replace(/\+''/g, '');
//.replace(/(\s|;|\}|^|\{)out\+=''\+/g,'$1out+=');

if (needhtmlencode) {
if (!c.selfcontained && _globals && !_globals._encodeHTML) _globals._encodeHTML = doT.encodeHTMLSource(c.doNotSkipEncoded);
Expand Down
10 changes: 5 additions & 5 deletions doT.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

doT.encodeHTMLSource = function(doNotSkipEncoded) {
var encodeHTMLRules = { "&": "&#38;", "<": "&#60;", ">": "&#62;", '"': '&#34;', "'": '&#39;', "/": '&#47;' },
matchHTML = doNotSkipEncoded ? /&|<|>|"|'|\//g : /&(?!#?\w+;)|<|>|"|'|\//g;
matchHTML = doNotSkipEncoded ? /[&<>"'\/]/g : /&(?!#?\w+;)|<|>|"|'|\//g;
return function(code) {
return code ? code.replace(matchHTML, function(m) {return encodeHTMLRules[m] || m;}) : "";
};
Expand All @@ -46,8 +46,8 @@
}

var startend = {
append: { start: "'+(''+", end: ")+'", startencode: "'+encodeHTML(" },
split: { start: "';out+=(''+", end: ");out+='", startencode: "';out+=encodeHTML(" }
append: { start: "'+(", end: ")+'", startencode: "'+encodeHTML(" },
split: { start: "';out+=(", end: ");out+='", startencode: "';out+=encodeHTML(" }
}, skip = /$^/;

function resolveDefs(c, block, def) {
Expand Down Expand Up @@ -117,8 +117,8 @@
})
+ "';return out;")
.replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r')
.replace(/(\s|;|\}|^|\{)out\+='';/g, '$1').replace(/\+''/g, '')
.replace(/(\s|;|\}|^|\{)out\+=''\+/g,'$1out+=');
.replace(/(\s|;|\}|^|\{)out\+='';/g, '$1').replace(/\+''/g, '');
//.replace(/(\s|;|\}|^|\{)out\+=''\+/g,'$1out+=');

if (needhtmlencode) {
if (!c.selfcontained && _globals && !_globals._encodeHTML) _globals._encodeHTML = doT.encodeHTMLSource(c.doNotSkipEncoded);
Expand Down
4 changes: 2 additions & 2 deletions doT.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/testdoT.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ describe('doT', function(){
global._encodeHTML = undefined;
doT.templateSettings.doNotSkipEncoded = true;
assert.equal(doT.template(definestemplate)({foo:"&amp;"}), "<div>&#38;amp;</div>");
assert.equal(doT.template('{{!it.a}}')({a:"& < > / ' \""}), "&#38; &#60; &#62; &#47; &#39; &#34;");
assert.equal(doT.template('{{!"& < > / \' \\""}}')(), "&#38; &#60; &#62; &#47; &#39; &#34;");

});
});

Expand Down

0 comments on commit ae234eb

Please sign in to comment.