Safari 2.0.4 Fails on Unicode Escape Sequences in Regular Expressions

Fought with this one for quite some time today. We use a lot of client-side validation for input fields in the products I work on. While we repeat that validation on the server (as is the way with ASP.NET validation), the client-side validation is important to give the customer earlier feedback about invalid input.

Our products are written to work in a multilingual capacity so the validation expressions need to support characters above and beyond ASCII. That's great, but it also means we have some work to do to get the regular expressions to work the same on the client as they do on the server. I've blogged about this issue before.

ECMAScript standards indicate you use Unicode escape sequences to put these extended characters into regular expressions. So rather than literally putting é right in the expression, you put the equivalent Unicode escape sequence: \u00e9.

Safari 2.0.4 doesn't seem to handle Unicode escape sequences in its regular expression engine. It understands that code \u00e9 is equivalent to the literal character é, but if you ask in a regular expression if they match, they don't.

From what I can tell, there is no workaround. It just doesn't get Unicode escape sequences in JavaScript regular expressions.

I've put together some tests to illustrate the point (click for test page). Browsers that handle the issue correctly will read "true" for all cases; Safari 2.0.4 fails on the Regex tests.

Print | posted @ Tuesday, August 15, 2006 6:03 PM

Comments on this entry:

Gravatar # Re: Safari 2.0.4 Fails on Unicode Escape Sequences in Regular Expressions
by J at 8/15/2006 10:39 PM

I just filed a bug report about this to Apple. Hopefully it gets fixed...
Gravatar # Re: Safari 2.0.4 Fails on Unicode Escape Sequences in Regular Expressions
by Travis at 8/16/2006 10:39 AM

Looks like there are three inter-related bugs on this:

Bug 8043: unicode (\uhhhh) sequences unrecognized in regex
Bug 6257: Throw errors on invalid expressions/support non-PCRE regexp (KJS merge)
Bug 7253: Inline regex produces wrong results vs. creating new RegExp object

According to the bug reports, these look to be fixed in later builds of WebKit that haven't been integrated into Safari yet. According to this page, Safari 2.0.4 uses WebKit 418.8. The fix looks like it was introduced in WebKit 420.

I guess folks will have to wait until Apple rolls the latest into Safari.
Gravatar # Scott Hanselman's Computer Zen - Safari for Windows - First Impressions
by www.hanselman.com at 6/11/2007 1:30 PM

Your comment:

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 5 and 8 and type the answer here: