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

Error Parsing Integer with Leading/Trailing Underscore #442

Open
xokocodo opened this issue Mar 18, 2020 · 5 comments
Open

Error Parsing Integer with Leading/Trailing Underscore #442

xokocodo opened this issue Mar 18, 2020 · 5 comments

Comments

@xokocodo
Copy link

ScalarScanner.parse_int uses Integer() to parse items that match the INTEGER regex. Strings with leading/trailing underscores will fail to parse, even though they match the regex.

Example:

=> 1234
irb(main):012:0> Integer("_1234")
ArgumentError (invalid value for Integer(): "_1234")
irb(main):013:0> Integer("1234_")
ArgumentError (invalid value for Integer(): "1234_")
irb(main):014:0> ```
@maknz
Copy link

maknz commented Mar 19, 2020

👍, we're encountering this issue too. The bug was introduced between versions 3.0.2 and 3.1.0.

For example, we're hitting this with a value like 1234________5678, which should be (and is) treated like a string in 3.0.2.

Our workaround for now is to downgrade to 3.0.2 from Ruby 2.7's default 3.1.0.

@casperisfine
Copy link

I submitted a fix for it: #442

@casperisfine
Copy link

Woops, wrong issue number, sorry: #445

@ccutrer
Copy link
Contributor

ccutrer commented Jun 22, 2021

note that even with #438 merged in, there is still a regression with the string "0x_". It passes the regex validation, then the _ is stripped, and just "0x" is passed to Integer(), which then raises an error. My quick monkey-patch is

def parse_int(string)
  super
rescue ArgumentError
  string
end

@qnighy
Copy link

qnighy commented May 3, 2024

YAML.dump("0x_") also fails for the same reason.

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

Successfully merging a pull request may close this issue.

5 participants