From b83ae95d90347d828ac7b4d281b42123c8ce7f08 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 17 Oct 2007 14:14:27 +0000 Subject: [PATCH] prototype: Fix template evaluation with empty replacements. Closes #9692. --- CHANGELOG | 6 +++++- src/string.js | 2 +- test/unit/string.html | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 076be7e..59b8f25 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,13 @@ -*1.6.0_rc1* (October 16, 2007) +*SVN* + +* Fix template evaluation with empty replacements. Closes #9692. [Ryan McGeary] * Hash#toTemplateReplacements is an alias for Hash#toObject so you can once again pass hashes to Template#evaluate and String#interpolate. [sam] * Fix Event#is(Left|Middle|Right)Click in IE. Closes #7520 (again). [Mislav Marohnić] +*1.6.0_rc1* (October 16, 2007) + * Ensure Event.* generic methods work in IE, even when the event is not extended. [Viktor Kojouharov, Andrew Dupont] * Don't translate "keypress" events into "keydown" events. [sam] diff --git a/src/string.js b/src/string.js index 0a994e2..ff89433 100644 --- a/src/string.js +++ b/src/string.js @@ -246,7 +246,7 @@ var Template = Class.create({ var ctx = object, expr = match[3]; var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/, match = pattern.exec(expr); - if (match == null) return ''; + if (match == null) return before; while (match != null) { var comp = match[1].startsWith('[') ? match[2].gsub('\\\\]', ']') : match[1]; diff --git a/test/unit/string.html b/test/unit/string.html index 9241e52..023b5bb 100644 --- a/test/unit/string.html +++ b/test/unit/string.html @@ -305,6 +305,15 @@ template.evaluate({})); }}, + testTemplateEvaluationWithEmptyReplacement: function() {with(this) { + var template = new Template('##{}'); + assertEqual('#', template.evaluate({})); + assertEqual('#', template.evaluate({foo: 'bar'})); + + template = new Template('#{}'); + assertEqual('', template.evaluate({})); + }}, + testTemplateEvaluationWithFalses: function() {with(this) { var source = '#{zero}#{false_}#{undef}#{null_}#{empty}'; var falses = {zero:0, false_:false, undef:undefined, null_:null, empty:""};