5 ms·
It may not be clear till you read all the comments on the bug that the 9 which isn't matched is a FULLWIDTH DIGIT NINE. If you're using, e.g., [a-fA-F0-9] in a
by js2 8y ago
It may not be clear till you read all the comments on the bug that the 9 which isn't matched is a FULLWIDTH DIGIT NINE.
If you're using, e.g., [a-fA-F0-9] in any locale other than C/POSIX, you're going to have a bad time.
This is going to cause problems, and it's a shame the developers note this, but then seem to wash their hands of it. Perhaps glibc should do what the programmer means, not what they say. It's obvious the regex above intends to validate hex digits, so glibc should do that, standards (and locale) be damned, unless the programmer explictly opts in to the technically correct behavior. The documentation even says:
> Therefore, using [a-z] does not make much sense except in the C/POSIX locale.
If that range doesn't make sense except in the C/POSIX locale, then why interpret it in any other locale? Come on glibc... help us out here.
$0.02.
- icedchai 8y agoI agree. I actually thought this bug report was a late April fools joke.
- iforgotpassword 8y agoAt least make the new behavior optional and off by default. Iirc, some languages do this by requiring a modifier to the regexp, like /[0-9]/u
- emmelaich 8y agoAbsolutely. Using a 'range' should be an actual range, not a category.
- zeroimpl 8y agoThis suggests the only safe portable way to represent hex is one of these? [1234567890abcdefABCDEF] or [\dabcdefABCDEF] That sucks. Fortunately I don't use C, but I'm worried about this finding its way into other languages...
- js2 8y agoFor a POSIX regex, the correct way to match a hex digit is to use is [[:xdigit:]].
- zeroimpl 8y agoRight - would be great if more languages supported that, specifically Javascript.
- js2 8y agoJavascript defines regex ranges in terms of UTF-16 code units w/no consideration for locale, so you can use [a-fA-F0-9] and it will work as expected. The issue discussed in this bug is only relevant to POSIX regular expression ranges. Perhaps you're lamenting that there are so many different flavors of regular expression. I agree. Just the other day I had to give up on using a regex in a CloudFormation template to validate input because I could not get it to work as documented.
- js2 8y agoFollowup. The glibc developers came up with a solution that meets the standards without violating the principle of least surprise. See https://sourceware.org/bugzilla/show_bug.cgi?id=23393#c28 https://sourceware.org/bugzilla/show_bug.cgi?id=23393#c28 and https://www.sourceware.org/ml/libc-alpha/2018-07/msg00620.html https://www.sourceware.org/ml/libc-alpha/2018-07/msg00620.ht...