Javascript .normalize() causing error in Safari

1.6k views Asked by At

EDIT: Ok, sounds like .normalize() isn't as widely supported as I'd originally thought. So a modification to my below question: what do you consider the best workaround to normalize unicode on browsers like Safari that don't yet support this function?

Ok, some code I wrote that has been working fine on all browsers up until around a week ago is now broken on Safari only (all other browsers still work fine). I've honed in on the offending bit of code, but am still not sure why it's a problem for Safari. This bit of code is supposed to be comparing two URL substrings (example: "Williams%2C+John%2C+1932-") to make sure that they are the same. Sometimes the strings contain diacritics, spaces and other problematic characters, hence the decodeURI (for the first string) and normalizing (for both strings).

What I do know is that if I remove both .normalize('NFD') commands, the code again works fine... but I need that normalize command in there because there are times when one string will use precomposed diacritics and the other will use decomposed (and for my purposes I want to consider them a match). I'm curious if anyone knows why .normalize() could be causing problems in Safari but no other browser.

if(decodeURI(urlmatch).normalize('NFD')==lowernopuncplus.normalize('NFD')){
            window.open(url);
        }
        else{
            alert("Error");
        }

And here's Safari's error code:

'undefined' is not a function (evaluating 'decodeURI(urlmatch).normalize('NFD')')
0

There are 0 answers