Skip to content
This repository was archived by the owner on Sep 25, 2021. It is now read-only.

Commit a35729f

Browse files
committed
false and zero values are not treated as 0
1 parent 9b0f41f commit a35729f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
data
141141
)
142142
).to.be(
143-
''
143+
'00'
144144
);
145145
});
146146

@@ -154,7 +154,7 @@
154154
data
155155
)
156156
).to.be(
157-
''
157+
'00'
158158
);
159159
});
160160

tmpl.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
tmpl(tmpl.load(str)) :
2323
new Function(
2424
tmpl.arg + ',tmpl',
25-
"var _e=tmpl.encode" + tmpl.helper + ",_s='" +
25+
"var _e=tmpl.encode" + tmpl.helper + ",_r=tmpl.raw" + tmpl.helper + ",_s='" +
2626
str.replace(tmpl.regexp, tmpl.func) +
2727
"';return _s;"
2828
);
@@ -48,7 +48,7 @@
4848
if (p2 === "=") {
4949
return "'+_e(" + p3 + ")+'";
5050
}
51-
return "'+(" + p3 + "||'')+'";
51+
return "'+_r(" + p3 + ")+'";
5252
}
5353
if (p4) { // evaluation start tag: {%
5454
return "';";
@@ -66,13 +66,16 @@
6666
"'" : "'"
6767
};
6868
tmpl.encode = function (s) {
69-
return String(s || "").replace(
69+
return String((s === 0) ? '0' : (s || "")).replace(
7070
tmpl.encReg,
7171
function (c) {
7272
return tmpl.encMap[c] || "";
7373
}
7474
);
7575
};
76+
tmpl.raw = function (s) {
77+
return String((s === 0) ? '0' : (s || ""));
78+
};
7679
tmpl.arg = "o";
7780
tmpl.helper = ",print=function(s,e){_s+=e&&(s||'')||_e(s);}" +
7881
",include=function(s,d){_s+=tmpl(s,d);}";

0 commit comments

Comments
 (0)