Project

General

Profile

Actions

Bug #17395

closed

Kernel::Integer does not raise ArgumentError for strings with whitespace padding

Added by mikelikesbikes (Mike Busch) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin18]
[ruby-core:101464]

Description

According to the Kernel::Integer docs, ArgumentError should be raised if the argument is a String and doesn't conform with numerical representation. However, it appears that Kernel::Integer does not raise ArgumentError when a string contains leading or trailing whitespace.

Ruby Version: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin18]

Reproduce Steps:

Integer(" 1")
Integer("1 ")

Actual Results:
both parse to a valid Integer, 1, no exception is raised.

Expected Results:
both should raise ArgumentError because they contain non-numerical characters

Actions #1

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Status changed from Open to Closed

Applied in changeset git|a039dc018ccf34e217f767eac500b9400c58f069.


[DOC] Described "numeric representation" more precisely [ci skip]

[Bug #17395]

Actions

Also available in: Atom PDF

Like0
Like0