moodmosaic / Fare

Port of Java dk.brics.automaton and xeger, mostly used for generating strings that match a specific regular expression.
http://www.brics.dk/automaton/
MIT License
182 stars 43 forks source link

Class of char wrongly parsed #67

Open bkqc opened 3 months ago

bkqc commented 3 months ago

I have this code using Xeger package 2.2.1 that I used to test an AutoFixture call that is often crashing (this RegEx is normally in a RegularExpressionAttribute annotation). new Fare.Xeger(@"^\s*[0-9\s]{0,6}\s*$").Generate(); that generates this C# string. " s\t \t "

Obviously, the character "s" is not valid using this RegEx.

To reproduce, I called the previous code multiple time in the Execution window in Visual Studio 2022. The global results were

new Fare.Xeger(@"^\s*[0-9\s]{0,6}\s*$").Generate();
""
new Fare.Xeger(@"^\s*[0-9\s]{0,6}\s*$").Generate();
""
new Fare.Xeger(@"^\s*[0-9\s]{0,6}\s*$").Generate();
"  s\t \t  "
new Fare.Xeger(@"^\s*[0-9\s]{0,6}\s*$").Generate();
"4\t\t"

NB Note how the [0-9\s] part is almost never used. This seems bad in a randomized context.