From 37254587bec2683b78ce51693eceba8273dc5d93 Mon Sep 17 00:00:00 2001 From: Jan Pieter Waagmeester Date: Mon, 21 Mar 2016 14:36:21 +0100 Subject: [PATCH] Allow dashes in template placeholders + tests --- spec/suites/core/UtilSpec.js | 6 ++++++ src/core/Util.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/suites/core/UtilSpec.js b/spec/suites/core/UtilSpec.js index b4cd2442..4b97c087 100644 --- a/spec/suites/core/UtilSpec.js +++ b/spec/suites/core/UtilSpec.js @@ -211,6 +211,7 @@ describe('Util', function () { expect(str).to.eql('Hello Vlad and Dave!'); }); + it('does not modify text without a token variable', function () { expect(L.Util.template('foo', {})).to.eql('foo'); }); @@ -226,6 +227,11 @@ describe('Util', function () { L.Util.template(undefined, {foo: 'bar'}); }).to.throwError(); }); + + it('allows underscores and dashes in placeholders', function () { + expect(L.Util.template('{nice_stuff}', {'nice_stuff': 'foo'})).to.eql('foo'); + expect(L.Util.template('{-y}', {'-y': 1})).to.eql('1'); + }); }); describe('#isArray', function () { diff --git a/src/core/Util.js b/src/core/Util.js index d7c681c5..f72058b0 100644 --- a/src/core/Util.js +++ b/src/core/Util.js @@ -141,7 +141,7 @@ L.Util = { }); }, - templateRe: /\{ *([\w_]+) *\}/g, + templateRe: /\{ *([\w_\-]+) *\}/g, isArray: Array.isArray || function (obj) { return (Object.prototype.toString.call(obj) === '[object Array]');