Skip to content

Commit

Permalink
Go back to scanning string from current character
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
theory committed Jul 20, 2024
1 parent 4d770d6 commit 7e14cf6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/semver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions test/sql/corpus.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 7e14cf6

Please sign in to comment.