From 7e14cf61fb68d1d97090af8a25c4f7291a6f91f3 Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Sat, 20 Jul 2024 15:15:24 -0400 Subject: [PATCH] Go back to scanning string from current character Turns out `patch` wasn't populated yet, so my last commit was scanning nothing. Finally found the bug: it need to start scanning at `atchar`, not `len - atchar`. Wild that this never came up before! Only found it just now by, at the last second, testing the example from #70: `0.0.0-00010101000000-000000000000`. Now included in the test corpus. --- src/semver.c | 6 +++--- test/sql/corpus.sql | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/semver.c b/src/semver.c index 85d1c2f..d63da30 100644 --- a/src/semver.c +++ b/src/semver.c @@ -214,12 +214,12 @@ semver* parse_semver(char* str, bool lax, bool throw, bool* bad) { if (i >= 1 && (i == 1 || patch[i-2] == '.') && patch[i-1] == '0' && isdigit(next)) { pred = true; // Numeric identifiers must not include a leading 0. Scan ahead. - for (p = i; p < strlen(patch); p++) { - if (patch[p] == '.') { + for (p = atchar; p < len; p++) { + if (str[p] == '.') { // We got to the end of this bit. break; } - if (isalpha(patch[p]) || patch[p] == '-') { + if (isalpha(str[p]) || str[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/sql/corpus.sql b/test/sql/corpus.sql index 0018a10..c0fe98e 100644 --- a/test/sql/corpus.sql +++ b/test/sql/corpus.sql @@ -6,7 +6,7 @@ BEGIN; \i test/pgtap-core.sql CREATE EXTENSION semver; -SELECT plan(75); +SELECT plan(76); --SELECT * FROM no_plan(); -- Valid Semantic Versions @@ -47,7 +47,8 @@ SELECT lives_ok( '1.0.0-0010-1234', '1.0.0-1.2.3-1234', '1.0.0-1234', - '1.0.0-4321' + '1.0.0-4321', + '0.0.0-00010101000000-000000000000' -- ]) AS v;