From 6324de20c60dad7be8ec32ab52e7f3a3223fdc97 Mon Sep 17 00:00:00 2001 From: Elise Wood Date: Fri, 26 Feb 2010 01:49:35 -0600 Subject: [PATCH] tests for null value change --- examples/null_string.html | 5 +++++ examples/null_string.js | 9 +++++++++ examples/null_string.txt | 5 +++++ mustache.js | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 examples/null_string.html create mode 100644 examples/null_string.js create mode 100644 examples/null_string.txt diff --git a/examples/null_string.html b/examples/null_string.html new file mode 100644 index 0000000..12bcb08 --- /dev/null +++ b/examples/null_string.html @@ -0,0 +1,5 @@ +Hello {{name}} +glytch {{glytch}} +binary {{binary}} +value {{value}} +numeric {{numeric}} \ No newline at end of file diff --git a/examples/null_string.js b/examples/null_string.js new file mode 100644 index 0000000..93414a1 --- /dev/null +++ b/examples/null_string.js @@ -0,0 +1,9 @@ +var null_string = { + name: "Elise", + glytch: true, + binary: false, + value: null, + numeric: function() { + return NaN; + } +}; diff --git a/examples/null_string.txt b/examples/null_string.txt new file mode 100644 index 0000000..827569b --- /dev/null +++ b/examples/null_string.txt @@ -0,0 +1,5 @@ +Hello Elise +glytch true +binary false +value +numeric NaN diff --git a/mustache.js b/mustache.js index e356521..5f6a601 100644 --- a/mustache.js +++ b/mustache.js @@ -194,7 +194,7 @@ var Mustache = function() { Does away with nasty characters */ escape: function(s) { - return (s ? s.toString() : "").replace(/[&"<>\\]/g, function(s) { + return ((s == null) ? "" : s).toString().replace(/[&"<>\\]/g, function(s) { switch(s) { case "&": return "&"; case "\\": return "\\\\";;