Skip to content

🐛 Less strict number string coercion, to match RFCs#680

Merged
nevans merged 3 commits into
masterfrom
less-strict-number-coersion
May 18, 2026
Merged

🐛 Less strict number string coercion, to match RFCs#680
nevans merged 3 commits into
masterfrom
less-strict-number-coersion

Conversation

@nevans
Copy link
Copy Markdown
Collaborator

@nevans nevans commented May 18, 2026

Convert most NumValidator#coerce_{type} methods to a simpler /\A\d+\z/ regexp.

The formal syntax in the RFCs would appear to allow any of zero-able numbers to be zero-padded: i.e, not only "0" => 0, but also "000" => 0 and "012" => 12!

RFC9051:

number          = 1*DIGIT
number64        = 1*DIGIT
nz-number       = digit-nz *DIGIT
nz-number64     = digit-nz *DIGIT

RFC7162:

mod-sequence-value  = 1*DIGIT
mod-sequence-valzer = "0" / mod-sequence-value

I dont' like this. I'd prefer that the specs for number, number64, and mod-sequence-value were stricter, like my original regexps:

number              = "0" / nz-number
number64            = "0" / nz-number64
mod-sequence-valzer = "0" / mod-sequence-value
nz-number           = digit-nz *DIGIT
nz-number64         = digit-nz *DIGIT
mod-sequence-value  = digit-nz *DIGIT

... but they're not!

A future release may add an upper limit to how many prefix zeros can be added, to prohibit goofy numbers like "0000000000000000000000000001". But that's a lot more important for the regexps used by ResponseReader and ResponseParser than it is for the regexps used by NumValidator.

nevans added 3 commits May 17, 2026 15:04
I was resisting the temptation to go all meta-programming with these
tests.  But they got too big, and I want to add different types of
examples that would require too many changes.
Extract `#test_method_invocation`, which simplifies all tests to either
`method(input) => result` or `method(input) raises Exception`.
The formal syntax in the RFCs would appear to allow any of zero-able
numbers to be zero-padded: i.e, not only `"0" => 0`, but also `"000" =>
0` and `"012" => 12`!

[RFC9051](https://www.rfc-editor.org/rfc/rfc9051#name-formal-syntax):
```abnf
number          = 1*DIGIT
number64        = 1*DIGIT
nz-number       = digit-nz *DIGIT
nz-number64     = digit-nz *DIGIT
```

[RFC7162](https://www.rfc-editor.org/rfc/rfc7162.html#section-7):
```abnf
mod-sequence-value  = 1*DIGIT
mod-sequence-valzer = "0" / mod-sequence-value
```

I dont' like this.  I'd prefer that the specs for `number`, `number64`,
and `mod-sequence-value` were stricter, like my original regexps:
```abnf
number          = "0" / nz-number
number64        = "0" / nz-number64
nz-number       = digit-nz *DIGIT
nz-number64     = digit-nz *DIGIT
mod-sequence-value  = number64
mod-sequence-valzer = nz-number64
```

... but they're not!

A future release may add an upper limit to how many prefix zeros can be
added, to prohibit goofy numbers like `"0000000000000000000000000001"`.
@nevans nevans force-pushed the less-strict-number-coersion branch from 700d43c to 1810d39 Compare May 18, 2026 12:59
@nevans nevans merged commit 1ca1a28 into master May 18, 2026
39 checks passed
@nevans nevans deleted the less-strict-number-coersion branch May 18, 2026 13:10
@nevans nevans added the bug Something isn't working label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant