From d17834aeb01c01fa340a931636f43dfef084d149 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Mon, 9 Apr 2012 22:49:12 -0400 Subject: [PATCH] Fix #547 - _.templateSettings is unchanged by custom settings. --- test/utility.js | 6 ++++++ underscore.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/test/utility.js b/test/utility.js index a367dc1cf..696b7819d 100644 --- a/test/utility.js +++ b/test/utility.js @@ -186,4 +186,10 @@ $(document).ready(function() { strictEqual(_.template(s)(data), 'x') }); + test('#547 - _.templateSettings is unchanged by custom settings.', function() { + ok(!_.templateSettings.variable); + _.template('', {}, {variable: 'x'}); + ok(!_.templateSettings.variable); + }); + }); diff --git a/underscore.js b/underscore.js index 40f23b25d..55e13e21a 100644 --- a/underscore.js +++ b/underscore.js @@ -952,7 +952,7 @@ // Underscore templating handles arbitrary delimiters, preserves whitespace, // and correctly escapes quotes within interpolated code. _.template = function(text, data, settings) { - settings = _.extend(_.templateSettings, settings); + settings = _.defaults(settings || {}, _.templateSettings); // Compile the template source, taking care to escape characters that // cannot be included in a string literal and then unescape them in code