zspecza / common-tags

🔖 Useful template literal tags for dealing with strings in ES2015+

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix TypeError of `stripIndent` when use invalid use of octal escape sequences in template strings

seongwon-kang opened this issue · comments

Currently this code will give an TypeError.

stripIndent`
    \4
`

Result is:

/home/vagrant/test/node_modules/common-tags/lib/stripIndentTransformer/stripIndentTransformer.js:20
        var match = endResult.match(/^[^\S\n]*(?=\S)/gm);
                              ^

TypeError: Cannot read property 'match' of undefined
    at Object.onEndResult (/home/vagrant/test/node_modules/common-tags/lib/stripIndentTransformer/stripIndentTransformer.js:20:31)
    at cb (/home/vagrant/test/node_modules/common-tags/lib/TemplateTag/TemplateTag.js:161:50)
    at Array.reduce (<anonymous>)
    at TemplateTag.transformEndResult (/home/vagrant/test/node_modules/common-tags/lib/TemplateTag/TemplateTag.js:163:32)
    at TemplateTag.tag (/home/vagrant/test/node_modules/common-tags/lib/TemplateTag/TemplateTag.js:54:20)

Because of SyntaxError was raised in template string, and TemplateTag.tag will get undefined string.

SyntaxError: Octal escape sequences are not allowed in template strings.