From 2dc53223e5b12b7ef5d7702df1301fdb0c4e7227 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 7 Sep 2012 21:17:00 -0700 Subject: [PATCH] Ensure `_.template` works with "interpolate" delimiters containing ternary operators. [closes #68] Former-commit-id: 287df2ef5802ea6db743da5f211e480d6b0f85c9 --- lodash.js | 2 +- test/test.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index 5e25bbfde..569218e68 100644 --- a/lodash.js +++ b/lodash.js @@ -54,7 +54,7 @@ var oldDash = window._; /** Used to detect delimiter values that should be processed by `tokenizeEvaluate` */ - var reComplexDelimiter = /[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/; + var reComplexDelimiter = /[-?+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/; /** Used to match HTML entities */ var reEscapedHtml = /&(?:amp|lt|gt|quot|#x27);/g; diff --git a/test/test.js b/test/test.js index dceb709da..61b7e8475 100644 --- a/test/test.js +++ b/test/test.js @@ -1499,6 +1499,11 @@ var compiled = _.template(''); equal(compiled({ 'type': 1 }), ''); }); + + test('should work with "interpolate" delimiters containing ternary operators', function() { + var compiled = _.template('<%= value ? value : "b" %>'); + equal(compiled({ 'value': 'a' }), 'a'); + }); }()); /*--------------------------------------------------------------------------*/