string-template
string-template copied to clipboard
Properties with underscore not working in compile mode
Using version 1.0.0 on node v6.9.4:
const format = require("string-template")
const compile = require("string-template/compile")
const vars = {
hostName: 'my.only.host.com',
host_tenant: 'only',
host_lane: 'prd',
subdomain: 'my.only',
}
console.log(format('http://{hostName}-{host_tenant}-{host_lane}-{subdomain}', vars))
// Logs out "http://my.only.host.com-only-prd-my.only"
const template = compile('http://{hostName}-{host_tenant}-{host_lane}-{subdomain}')
console.log(template(vars))
// Logs out "http://my.only.host.com-{host_tenant}-{host_lane}-my.only"
Can be reproduced here: https://runkit.com/58827adb4ddfcf0014890d06/58827adb4ddfcf0014890d07
I believe this is fixed by changing this line: https://github.com/Matt-Esch/string-template/blob/master/compile.js#L4 to allow an _
in its charset, but you may want to support other valid characters in variable names such as $