fent / randexp.js

Create random strings that match a given regular expression.
http://fent.github.io/randexp.js/
MIT License
1.83k stars 91 forks source link

I think the 'control char' escapes such as \ca are not handled correctly #104

Open anentropic opened 4 years ago

anentropic commented 4 years ago

JS regex flavour defines a set of escape codes prefixed with \c:

\cX: Matches a control character using caret notation, where "X" is a letter from A–Z (corresponding to codepoints U+0001–U+001F). For example, /\cM/ matches "\r" in "\r\n".

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes https://www.ecma-international.org/ecma-262/5.1/#sec-15.10.1

Another example:

/\ca/.test('\u0001')
-> true

But currently it seems like RandExp treats \ca as "escaped c followed by a":

new RandExp(/\ca/).gen()
-> "ca"

/\ca/.test("ca")
-> false