Skip to content

Commit c693044

Browse files
committed
more template string validation
1 parent 587fd7c commit c693044

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

js/tmpl.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
(function ($) {
1919
"use strict";
2020
var tmpl = function (str, data) {
21+
if(typeof(str) !== 'string'){
22+
throw new Error('str must be a string');
23+
}
2124
var f = !/[^\w\-\.:]/.test(str) ? tmpl.cache[str] = tmpl.cache[str] ||
2225
tmpl(tmpl.load(str)) :
2326
new Function(
@@ -32,7 +35,11 @@
3235
};
3336
tmpl.cache = {};
3437
tmpl.load = function (id) {
35-
return document.getElementById(id).innerHTML;
38+
var node = document.getElementById(id);
39+
if(!node){
40+
throw new Error('DOM Node '+id+' not found');
41+
}
42+
return node.innerHTML;
3643
};
3744
tmpl.regexp = /([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g;
3845
tmpl.func = function (s, p1, p2, p3, p4, p5) {

0 commit comments

Comments
 (0)