Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure strings that may be confused as YAML1.2 numbers are quoted #628

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adammw
Copy link

@adammw adammw commented May 10, 2023

Ensure strings that may be confused as YAML1.2 numbers are quoted.

Example: 0o123 or 1e3 strings in Ruby will be printed without quotation marks, resulting in them changing to numbers in a YAML1.2-parser (like that used in Go).

Fixes #627

Comment on lines +176 to +182
assert_match(/'0o17'/, Psych.dump({'a' => '0o17'}))
assert_match(/'0o111'/, Psych.dump({'a' => '0o111'}))

# YAML 1.2 float Number
assert_match(/'12e03'/, Psych.dump({'a' => '12e03'}))
assert_match(/'1.2e3'/, Psych.dump({'a' => '1.2e3'}))
assert_match(/".2e3"/, Psych.dump({'a' => '.2e3'}))
Copy link
Member

@nobu nobu Jun 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

. (any character) does not seem what you want here.

Suggested change
assert_match(/'0o17'/, Psych.dump({'a' => '0o17'}))
assert_match(/'0o111'/, Psych.dump({'a' => '0o111'}))
# YAML 1.2 float Number
assert_match(/'12e03'/, Psych.dump({'a' => '12e03'}))
assert_match(/'1.2e3'/, Psych.dump({'a' => '1.2e3'}))
assert_match(/".2e3"/, Psych.dump({'a' => '.2e3'}))
assert_include(Psych.dump({'a' => '0o17'}), "'0o17'")
assert_include(Psych.dump({'a' => '0o111'}), "'0o111'")
# YAML 1.2 float Number
assert_include(Psych.dump({'a' => '12e03'}), "'12e03'")
assert_include(Psych.dump({'a' => '1.2e3'}), "'1.2e3'")
assert_include(Psych.dump({'a' => '.2e3'}), '".2e3"')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the last ".2e3" seems from YAML 1.1, right?

@djhoese
Copy link

djhoese commented Oct 9, 2024

@adammw Any chance you have time to continue working on this? I've run into this same problem where strings (git commit SHAs) that look like scientific notation are dumped with no quotes around them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

YAML string in exponential format cannot be loaded by YAML 1.2 parser
3 participants