From 4d770d6796b627c427914d7d2afba6347aebf814 Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Sat, 20 Jul 2024 14:54:26 -0400 Subject: [PATCH] Fix prerelease with leading 0 scanning 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. --- src/semver.c | 8 ++++---- test/expected/corpus.out | 6 +----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/semver.c b/src/semver.c index 92cc7ea..85d1c2f 100644 --- a/src/semver.c +++ b/src/semver.c @@ -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; diff --git a/test/expected/corpus.out b/test/expected/corpus.out index 0accb97..97ec5f7 100644 --- a/test/expected/corpus.out +++ b/test/expected/corpus.out @@ -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 @@ -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