Skip to content

Commit

Permalink
Fix prerelease with leading 0 scanning
Browse files Browse the repository at this point in the history
It was starting from the wrong place, so sometimes found characters not
part of the patch. I couldn't figure out the proper incantation with
`len`. So just only scan the patch part to avoid the whole issue.

Restore the expected test output to remove the error.
  • Loading branch information
theory committed Jul 20, 2024
1 parent ac5e2b5 commit 4d770d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/semver.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ semver* parse_semver(char* str, bool lax, bool throw, bool* bad) {
if ((started_prerel || started_meta) && !skip_char) {
if (i >= 1 && (i == 1 || patch[i-2] == '.') && patch[i-1] == '0' && isdigit(next)) {
pred = true;
// Scan ahead.
for (p = len - atchar; p < len; p++) {
if (str[p] == '.') {
// Numeric identifiers must not include a leading 0. Scan ahead.
for (p = i; p < strlen(patch); p++) {
if (patch[p] == '.') {
// We got to the end of this bit.
break;
}
if (isalpha(str[p]) || str[p] == '-') {
if (isalpha(patch[p]) || patch[p] == '-') {
// If there is a letter or a dash, it's okay to start with a leading 0.
pred = false;
break;
Expand Down
6 changes: 1 addition & 5 deletions test/expected/corpus.out
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ not ok 35 - "99999999999999999999999.999999999999999999.99999999999999999" is a
# died: XX000: bad semver value '99999999999999999999999.999999999999999999.99999999999999999': version number exceeds 31-bit range
ok 36 - "1" is not a valid semver
ok 37 - "1.2" is not a valid semver
not ok 38 - "1.2.3-0123" is not a valid semver
# Failed test 38: ""1.2.3-0123" is not a valid semver"
# caught: no exception
# wanted: an exception
ok 38 - "1.2.3-0123" is not a valid semver
ok 39 - "1.2.3-0123.0123" is not a valid semver
ok 40 - "1.1.2+.123" is not a valid semver
ok 41 - "+invalid" is not a valid semver
Expand Down Expand Up @@ -80,4 +77,3 @@ ok 72 - "+justmeta" is not a valid semver
ok 73 - "9.8.7+meta+meta" is not a valid semver
ok 74 - "9.8.7-whatever+meta+meta" is not a valid semver
ok 75 - "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12" is not a valid semver
# Looks like you failed 1 test of 75

0 comments on commit 4d770d6

Please sign in to comment.