Regular expression /\d/ matches "digits" other than

View: New views
2 Messages — Rating Filter:   Alert me  

Regular expression /\d/ matches "digits" other than

by Igor Tandetnik :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

/\d/.test("\uFF11")

returns true. U+FF11 is FULLWIDTH DIGIT ONE, and happens to have Unicode
class Nd (decimal number). However, Ecma-262 (the standard for
EcmaScript aka JavaScript) explicitly states:

15.10.2.12 CharacterClassEscape
The production CharacterClassEscape :: d evaluates by returning the
ten-element set of characters containing the characters 0 through 9
inclusive.

So accepting "digits" other than [0-9] appears to be a bug. Am I missing
something obvious?


I wouldn't mind this behavior, if things like parseInt would also
understand the same set of digits. I submit it should be the case that,
modulo overflow, for every (short enough) string s, if /^\d+$/.test(s)
returns true then parseInt(s, 10) should return a number other than NaN.

Yes, I realize that I can replace \d with [0-9] and \D with [^0-9]. This
makes even moderately complicated regular expressions considerably
harder to read though.

Igor Tandetnik


_______________________________________________
dev-i18n mailing list
dev-i18n@...
https://lists.mozilla.org/listinfo/dev-i18n

Re: Regular expression /\d/ matches "digits" other than

by Martin Honnen-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Igor Tandetnik wrote:

> /\d/.test("\uFF11")
>
> returns true. U+FF11 is FULLWIDTH DIGIT ONE, and happens to have Unicode
> class Nd (decimal number). However, Ecma-262 (the standard for
> EcmaScript aka JavaScript) explicitly states:
>
> 15.10.2.12 CharacterClassEscape
> The production CharacterClassEscape :: d evaluates by returning the
> ten-element set of characters containing the characters 0 through 9
> inclusive.
>
> So accepting "digits" other than [0-9] appears to be a bug. Am I missing
> something obvious?

Looks like a long standing bug in Spidermonkey. Rhino gives false for
that example.
I have filed <https://bugzilla.mozilla.org/show_bug.cgi?id=378738>.




--

        Martin Honnen
        http://JavaScript.FAQTs.com/
_______________________________________________
dev-i18n mailing list
dev-i18n@...
https://lists.mozilla.org/listinfo/dev-i18n