Skip to content

Commit

Permalink
#7 the dollar character is not well supported (#8)
Browse files Browse the repository at this point in the history
* #7 the dollar character is not well supported

* #7 the dollar character is not well supported

* #7 the dollar character is not well supported
  • Loading branch information
OlivierB-OB authored and ralphtheninja committed Jun 21, 2018
1 parent 9ea6b80 commit 7c3398b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = function (opts) {

return function (template, values) {
Object.keys(values).forEach(function (key) {
template = template.replace(regExp(key), values[key])
var value = String(values[key]).replace(/\$/g, '$$$$')
template = template.replace(regExp(key), value)
})
return template
}
Expand Down
20 changes: 20 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,23 @@ test('whitespace-insensitive', function (t) {
}), 'FOOFOOFOO', 'expands one placeholder many times')
t.end()
})

test('dollar escape', function (t) {
var expand = Expand()
t.equal(expand('before {foo} after', {
foo: '$'
}), 'before $ after')
t.equal(expand('before {foo} after', {
foo: '$&'
}), 'before $& after')
t.equal(expand('before {foo} after', {
foo: '$`'
}), 'before $` after')
t.equal(expand('before {foo} after', {
foo: '$\''
}), 'before $\' after')
t.equal(expand('before {foo} after', {
foo: '$0'
}), 'before $0 after')
t.end()
})

0 comments on commit 7c3398b

Please sign in to comment.