sindresorhus/semver-regex

This regex is broken by design

Closed this issue · 4 comments

Issuehunt badges

Test it against the following data set, it will pass some non-conforming strings and fail to pass some that are conforming.

1.2.3----RC-SNAPSHOT.12.9.1--.12
1.0.0+0.build.1-rc.10000aaa-kk-0.1
99999999999999999999999.999999999999999999.99999999999999999
Begin Invalid

1
1.2
1.2.3-0123
1.2.3-0123.0123
1.1.2+.123
+invalid
-invalid
-invalid+invalid
-invalid.01
alpha
alpha.beta
alpha.beta.1
alpha.1
alpha+beta
alpha_beta
alpha.
alpha..
beta
1.0.0-alpha_beta
-alpha.
1.0.0-alpha..
1.0.0-alpha..1
1.0.0-alpha...1
1.0.0-alpha....1
1.0.0-alpha.....1
1.0.0-alpha......1
1.0.0-alpha.......1
01.1.1
1.01.1
1.1.01
1.2
1.2.3.DEV
1.2-SNAPSHOT
1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788
1.2-RC-SNAPSHOT
-1.0.3-gamma+b7718
+justmeta
9.8.7+meta+meta
9.8.7-whatever+meta+meta
99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12

See semver/semver/issues/59.

stroncium earned $70.00 by resolving this issue!

@IssueHunt has funded $70.00 to this issue.


I can't any fault with the regex itself other than it is giving true for some wrong versions because of \b present in the start and end (regex only matches the correct part but using .test() would return true https://regex101.com/r/sezmjS/2 ) Apparently it was used instead of ^ and $ so that people can use functions like match and exec. Using the same regex for test and other functions doesn't appear to be possible. I am sorry if I've failed to understand something. Do correct me if I have.

@ammarbinfaisal, just try testing it against the test data I posted. It can't possibly work because it does not properly take into account, all of the SemVer rules. It is one of many dozens of naive SemVer regex's.

@sindresorhus has rewarded $63.00 to @stroncium. See it on IssueHunt

  • 💰 Total deposit: $70.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $7.00