Skip to content

Commit e8c88eb

Browse files
committed
remove leading and trailing spaces before interpolating key
1 parent 48096b8 commit e8c88eb

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/string.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ string.js - Copyright (C) 2012-2014, JP Richardson <[email protected]>
409409
var matches = s.match(r) || [];
410410

411411
matches.forEach(function(match) {
412-
var key = match.substring(opening.length, match.length - closing.length);//chop {{ and }}
412+
var key = match.substring(opening.length, match.length - closing.length).trim();//chop {{ and }}
413413
if (typeof values[key] != 'undefined')
414414
s = s.replace(match, values[key]);
415415
});

test/string.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,12 @@
486486
describe('- template(values, [open], [close])', function() {
487487
it('should return the string replaced with template values', function() {
488488
var str = "Hello {{name}}! How are you doing during the year of {{date-year}}?"
489-
var values = {name: 'JP', 'date-year': 2013}
489+
var values = {greet: 'Hello', name: 'JP', 'date-year': 2013}
490490
EQ (S(str).template(values).s, 'Hello JP! How are you doing during the year of 2013?')
491491

492+
var str = "{{greet }} {{ name}}! How are you doing during the year of {{ date-year }}?";
493+
EQ (S(str).template(values).s, 'Hello JP! How are you doing during the year of 2013?')
494+
492495
str = "Hello #{name}! How are you doing during the year of #{date-year}?"
493496
EQ (S(str).template(values, '#{', '}').s, 'Hello JP! How are you doing during the year of 2013?')
494497

0 commit comments

Comments
 (0)