Skip to content

fix: Handle octals inside strings being parsed as integers - #2

Closed
Traxmaxx wants to merge 1 commit into
fabfuel:developfrom
Traxmaxx:fix/parse-numbers
Closed

fix: Handle octals inside strings being parsed as integers#2
Traxmaxx wants to merge 1 commit into
fabfuel:developfrom
Traxmaxx:fix/parse-numbers

Conversation

@Traxmaxx

Copy link
Copy Markdown
Contributor

There is a "bug" in the script where it reads a number represented as a string and converts it to a number instead. Turns out this is a feature!

Strings which look like octal for example 0119 are being converted to int. YAML does this to make sure it can do proper duplicate checks:

For example, the integer eleven can be written as "013" (octal) or "0xB" (hexadecimal). If both forms are used as keys in the same mapping, only a YAML processor which recognizes integer formats would correctly flag the duplicate key as an error.

YAML 1.2 will also not accept such strings anymore as the ruyaml maintainer explains:

YAML 1.2 no longer accepts strings that start with a 0 and solely consist of number characters as octal, you need to specify such strings with 0o[0-7]+ (zero + lower-case o for octal + one or more octal characters).

I'm not convinced that changing the behaviour and handling it manually like introduced in this PR is the right approach. IMHO we should specify strings like "0119" as !!str "0119" in all schemas instead. Not sure how well that will work with YAML 1.2 though 🤔

What is your opinion @fabfuel?

@Traxmaxx Traxmaxx closed this Oct 22, 2025
@Traxmaxx
Traxmaxx deleted the fix/parse-numbers branch October 24, 2025 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant