Allow dashes in template placeholders + tests

This commit is contained in:
Jan Pieter Waagmeester 2016-03-21 14:36:21 +01:00
parent b60e18d5c6
commit 37254587be
2 changed files with 7 additions and 1 deletions

View File

@ -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 () {

View File

@ -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]');