pomsky-lang / pomsky

A new, portable, regular expression language
https://pomsky-lang.org
Apache License 2.0
1.28k stars 19 forks source link

Range matches wrong numbers when allowing leading zeroes lower bound is shorter than upper bound #98

Closed Aloso closed 10 months ago

Aloso commented 10 months ago

Describe the bug

A range expression may match numbers bigger than the upper bound if the upper bound has leading zeroes and more digits than the lower bound. Furthermore, a range expression may match numbers smaller than the lower bound if it has more leading zeroes.

To Reproduce

^ range '1'-'050' $

This incorrectly matches the string 70.

^ range '05'-'1000' $

This incorrectly matches the string 001.

Expected behavior

Since it is not obvious what the above expression does (should it match the string 04? Should it match 004?) The above should be forbidden. Leading zeroes should only be allowed on the lower bound, unless the lower and upper bound have the same number of digits.