Commons Lang
  1. Commons Lang
  2. LANG-94

[lang] NumberUtils.isNumber allows illegal trailing characters

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      This bug report is based on a post to commons-dev from Eric Pugh.

      I am attaching a patch that includes the test case that Eric posted and two
      others that confirm that the current code will accept strings with trailing
      characters that are not type qualifiers.

      The patch also adds a check to NumberUtils.isNumber() that causes these strings
      to be rejected. Assuming that my understanding of the code is correct, this
      patch should fix the problem without changing behavior on other strings. All
      other tests succeed with the patch applied.

        Activity

        Hide
        Hirokazu Shimada added a comment -

        How do you do. I also found such a thing.
        The return value was true when "1.." was passed to NumberUtils.isNumber().
        I think that I want "1.." to be false since it is not a numerical value.

        Show
        Hirokazu Shimada added a comment - How do you do. I also found such a thing. The return value was true when "1.." was passed to NumberUtils.isNumber(). I think that I want "1.." to be false since it is not a numerical value.
        Hide
        Stephen Colebourne added a comment -

        Patch applied (minor changes)
        Thanks for spotting this one!

        Show
        Stephen Colebourne added a comment - Patch applied (minor changes) Thanks for spotting this one!
        Hide
        David Eric Pugh added a comment -

        Interesting.. I don't know why I thought that.. I thought I had a testcase
        that proved that a-f failed, g-z worked!

        At any rate, I added this testcase:
        val = "1z";
        assertTrue("isNumber(String) 15 Neg failed", !NumberUtils.isNumber
        (val));
        assertTrue("isNumber(String)/createNumber(String) 15 Neg failed", !
        checkCreateNumber(val));

        and it tanked... 1z apparently is a number according to NumberUtils.isNumber!

        Show
        David Eric Pugh added a comment - Interesting.. I don't know why I thought that.. I thought I had a testcase that proved that a-f failed, g-z worked! At any rate, I added this testcase: val = "1z"; assertTrue("isNumber(String) 15 Neg failed", !NumberUtils.isNumber (val)); assertTrue("isNumber(String)/createNumber(String) 15 Neg failed", ! checkCreateNumber(val)); and it tanked... 1z apparently is a number according to NumberUtils.isNumber!
        Hide
        Phil Steitz added a comment -

        Interesting. Are you sure about 1g, 2b, etc.? These return true for me. Looks
        to me like anything will be accepted as the last character as long as all
        charactres before it are numeric.

        Show
        Phil Steitz added a comment - Interesting. Are you sure about 1g, 2b, etc.? These return true for me. Looks to me like anything will be accepted as the last character as long as all charactres before it are numeric.
        Hide
        David Eric Pugh added a comment -

        I discovered one more thing...
        It turns out strings like 1a1 or fine, it only affects things like 1a, 1b,1c ->
        1f. 1g according to isNumber is false. So, I believe the issue is that it
        sees a number like 3b, and thinks it is hex!
        Eric

        Show
        David Eric Pugh added a comment - I discovered one more thing... It turns out strings like 1a1 or fine, it only affects things like 1a, 1b,1c -> 1f. 1g according to isNumber is false. So, I believe the issue is that it sees a number like 3b, and thinks it is hex! Eric
        Hide
        Phil Steitz added a comment -

        Created an attachment (id=6665)
        patches to NumberUtils, NumberUtilsTest

        Show
        Phil Steitz added a comment - Created an attachment (id=6665) patches to NumberUtils, NumberUtilsTest

          People

          • Assignee:
            Unassigned
            Reporter:
            Phil Steitz
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development