Strings matched by the encoding regular expression, but not found in … · googleask/JavaScript-Templates@b6d6bda · GitHub
Skip to content

Commit b6d6bda

Browse files
committed
Strings matched by the encoding regular expression, but not found in the encoding map are now removed from the output.
Added single quotes to the default characters to encode: ' => &blueimp#39; This allows safely using single quotes for attributes in HTML documents, e.g. for embedding JSON, which requires double quotes for its own properties and string values.
1 parent a557f70 commit b6d6bda

9 files changed

Lines changed: 29 additions & 31 deletions

File tree

README.md

Lines changed: 6 additions & 8 deletions

compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
/*
3-
* JavaScript Templates Compiler 2.0
3+
* JavaScript Templates Compiler 2.1.0
44
* https://github.com/blueimp/JavaScript-Templates
55
*
66
* Copyright 2011, Sebastian Tschan

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE HTML>
22
<!--
33
/*
4-
* JavaScript Templates Demo 2.0
4+
* JavaScript Templates Demo 2.1.0
55
* https://github.com/blueimp/JavaScript-Templates
66
*
77
* Copyright 2011, Sebastian Tschan

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blueimp-tmpl",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"title": "JavaScript Templates",
55
"description": "< 1KB lightweight, fast & powerful JavaScript templating engine with zero dependencies. Compatible with server-side environments like node.js, module loaders like RequireJS and all web browsers.",
66
"keywords": [

runtime.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Templates Runtime 2.0
2+
* JavaScript Templates Runtime 2.1.0
33
* https://github.com/blueimp/JavaScript-Templates
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -20,19 +20,19 @@
2020
};
2121
};
2222
tmpl.cache = {};
23-
tmpl.encReg = /[<>&"\x00]/g;
23+
tmpl.encReg = /[<>&"'\x00]/g;
2424
tmpl.encMap = {
25-
"<": "&lt;",
26-
">": "&gt;",
27-
"&": "&amp;",
28-
"\"": "&quot;",
29-
"\x00": ""
25+
"<" : "&lt;",
26+
">" : "&gt;",
27+
"&" : "&amp;",
28+
"\"" : "&quot;",
29+
"'" : "&#39;"
3030
};
3131
tmpl.encode = function (s) {
3232
return String(s || "").replace(
3333
tmpl.encReg,
3434
function (c) {
35-
return tmpl.encMap[c];
35+
return tmpl.encMap[c] || "";
3636
}
3737
);
3838
};

test/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE HTML>
22
<!--
33
/*
4-
* JavaScript Templates Test 2.0
4+
* JavaScript Templates Test 2.1.0
55
* https://github.com/blueimp/JavaScript-Templates
66
*
77
* Copyright 2011, Sebastian Tschan

test/test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Templates Test 2.0
2+
* JavaScript Templates Test 2.1.0
33
* https://github.com/blueimp/JavaScript-Templates
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -31,7 +31,7 @@
3131
nullValue: null,
3232
falseValue: false,
3333
zeroValue: 0,
34-
special: '<>&"\x00',
34+
special: '<>&"\'\x00',
3535
list: [1, 2, 3, 4, 5],
3636
func: function () {
3737
return this.value;
@@ -84,14 +84,14 @@
8484
it('Escape HTML special characters with {%=o.prop%}', function () {
8585
expect(
8686
tmpl('{%=o.special%}', data),
87-
'&lt;&gt;&amp;&quot;'
87+
'&lt;&gt;&amp;&quot;&#39;'
8888
);
8989
});
9090

9191
it('Allow HTML special characters with {%#o.prop%}', function () {
9292
expect(
9393
tmpl('{%#o.special%}', data),
94-
'<>&"\x00'
94+
'<>&"\'\x00'
9595
);
9696
});
9797

@@ -176,14 +176,14 @@
176176
it('Escape HTML special characters with print(data)', function () {
177177
expect(
178178
tmpl('{% print(o.special); %}', data),
179-
'&lt;&gt;&amp;&quot;'
179+
'&lt;&gt;&amp;&quot;&#39;'
180180
);
181181
});
182182

183183
it('Allow HTML special characters with print(data, true)', function () {
184184
expect(
185185
tmpl('{% print(o.special, true); %}', data),
186-
'<>&"\x00'
186+
'<>&"\'\x00'
187187
);
188188
});
189189

tmpl.js

Lines changed: 4 additions & 4 deletions

tmpl.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)