mathiasbynens / jsesc

Given some data, jsesc returns the shortest possible stringified & ASCII-safe representation of that data.
https://mths.be/jsesc
MIT License
716 stars 48 forks source link

Don’t replace `\x08` with `\b` in regular expressions #10

Open mathiasbynens opened 11 years ago

mathiasbynens commented 11 years ago

In regular expressions, \b has a different meaning than in strings (where it’s equivalent to '\x08'`):

/\b/.test('\b'); // false
/\x08/.test('\b'); // true

But jsesc incorrectly replaces \x08 in regular expressions with \b:

jsesc(/\x08/); // '/\\b/'

Only these single character escapes have the same meaning in regular expressions as in strings:

\f \n \r \t \v \0

Also see #11: \B, \w, \W, \s, \S, \d, \D, \cM, etc. should be preserved.

mathiasbynens commented 10 years ago

Relevant: https://github.com/mishoo/UglifyJS2/issues/54#issuecomment-32833742