asdf_enel_hak
asdf_enel_hak

Reputation: 7640

Chrome and Safari handles utf 8 differently then Firefox and IE if utf 8 character not hard coded issue?

note: question title is change as discussed in this meta Q&A

I'm using the jQuery bassistance autocomplete plugin with the accent plugin, so I have accent-free autocomplete. Accent map is like this:

map={'À':'A', 'İ':'I'};

I have problems with the character İ (turkish uppercase I with point). After I remove accents and convert to lowercase, I have this code:

   ("İstanbul").indexOf("is")

Firefox and IE gives 0, but Chrome and Safari gives -1.

charCodeAt(0) gives the same result in all browsers.

It seems that Chrome and Safari treats the normal I and the unaccented I different.

EDIT

Hi again, after about 5 months, I can finally add more source to my question.
Fortunately question date and my backups at that date helps me find source code.

BEFORE(TURKISH İ BUG) was fixed when I change my code with AFTER (WORKS OK).
Below I added also my document charshet(which is turkish)

I am not unicode expert, but if you let me guess about the "chrome vs ff" issue:
chrome handles the characther with "source code", I mean like \u0128
ff handles it with "visible characher", I mean like "İ"

BEFORE(TURKISH I BUG)

function remove_accent(str) {var map={'À':'A','Á':'A','Â':'A','Ã':'A','Ä':'A','Å':'A','Æ':'AE','Ç':'C','È':'E','É':'E','Ê':'E','Ë':'E','Ì':'I','Í':'I','Î':'I','Ï':'I','Ð':'D','Ñ':'N','Ò':'O','Ó':'O','Ô':'O','Õ':'O','Ö':'O','Ø':'O','Ù':'U','Ú':'U','Û':'U','Ü':'U','Ý':'Y','ß':'s','à':'a','á':'a','â':'a','ã':'a','ä':'a','å':'a','æ':'ae','ç':'c','è':'e','é':'e','ê':'e','ë':'e','ì':'i','í':'i','î':'i','ï':'i','ñ':'n','ò':'o','ó':'o','ô':'o','õ':'o','ö':'o','ø':'o','ù':'u','ú':'u','û':'u','ü':'u','ý':'y','ÿ':'y','Ā':'A','ā':'a','Ă':'A','ă':'a','Ą':'A','ą':'a','Ć':'C','ć':'c','Ĉ':'C','ĉ':'c','Ċ':'C','ċ':'c','Č':'C','č':'c','Ď':'D','ď':'d','Đ':'D','đ':'d','Ē':'E','ē':'e','Ĕ':'E','ĕ':'e','Ė':'E','ė':'e','Ę':'E','ę':'e','Ě':'E','ě':'e','Ĝ':'G','ĝ':'g','Ğ':'G','ğ':'g','Ġ':'G','ġ':'g','Ģ':'G','ģ':'g','Ĥ':'H','ĥ':'h','Ħ':'H','ħ':'h','Ĩ':'I','ĩ':'i','Ī':'I','ī':'i','Ĭ':'I','ĭ':'i','Į':'I','į':'i','İ':'I','ı':'i','IJ':'IJ','ij':'ij','Ĵ':'J','ĵ':'j','Ķ':'K','ķ':'k','Ĺ':'L','ĺ':'l','Ļ':'L','ļ':'l','Ľ':'L','ľ':'l','Ŀ':'L','ŀ':'l','Ł':'L','ł':'l','Ń':'N','ń':'n','Ņ':'N','ņ':'n','Ň':'N','ň':'n','ʼn':'n','Ō':'O','ō':'o','Ŏ':'O','ŏ':'o','Ő':'O','ő':'o','Œ':'OE','œ':'oe','Ŕ':'R','ŕ':'r','Ŗ':'R','ŗ':'r','Ř':'R','ř':'r','Ś':'S','ś':'s','Ŝ':'S','ŝ':'s','Ş':'S','ş':'s','Š':'S','š':'s','Ţ':'T','ţ':'t','Ť':'T','ť':'t','Ŧ':'T','ŧ':'t','Ũ':'U','ũ':'u','Ū':'U','ū':'u','Ŭ':'U','ŭ':'u','Ů':'U','ů':'u','Ű':'U','ű':'u','Ų':'U','ų':'u','Ŵ':'W','ŵ':'w','Ŷ':'Y','ŷ':'y','Ÿ':'Y','Ź':'Z','ź':'z','Ż':'Z','ż':'z','Ž':'Z','ž':'z','ſ':'s','ƒ':'f','Ơ':'O','ơ':'o','Ư':'U','ư':'u','Ǎ':'A','ǎ':'a','Ǐ':'I','ǐ':'i','Ǒ':'O','ǒ':'o','Ǔ':'U','ǔ':'u','Ǖ':'U','ǖ':'u','Ǘ':'U','ǘ':'u','Ǚ':'U','ǚ':'u','Ǜ':'U','ǜ':'u','Ǻ':'A','ǻ':'a','Ǽ':'AE','ǽ':'ae','Ǿ':'O','ǿ':'o'};var res='';for (var i=0;i<str.length;i++){c=str.charAt(i);res+=map[c]||c;}return res;}  

AFTER (WORKS OK)

var charToAccentedCharClassMap = {
// A to H
    'I': '[Iiı\xcc-\xcf\xec-\xef\u0128-\u0130\u0132\u0133\u01cf\u01d0\u0208-\u020b\u1d35\u1d62\u1e2c\u1e2d\u1ec8-\u1ecb\u2071\u2110\u2111\u2139\u2148\u2160-\u2163\u2165-\u2168\u216a\u216b\u2170-\u2173\u2175-\u2178\u217a\u217b\u24a4\u24be\u24d8\u337a\u33cc\u33d5\ufb01\ufb03\uff29\uff49]'
// J to Z
    };

function deaccent(accentedString) { var result = accentedString; for (var key in charToAccentedCharClassMap) { result = result.replace(new RegExp(charToAccentedCharClassMap[key], "g"), key); } //console.log(accentedString) return result.toLowerCase(); }

function remove_accent(str) { return deaccent(str).toLowerCase(); return str; }

EDIT2 little correction (SO user edited question but misses İ his keyboard):
He replaces ("İstanbul").indexOf("is") by ("istanbul").indexOf("is")

Upvotes: 1

Views: 3450

Answers (1)

Victor
Victor

Reputation: 9269

("istanbul").indexOf("is")
("Istanbul").toLowerCase().indexOf("ıs")

Lowercase 'I' is 'ı'. Is that what is happening here?

EDIT:

Probably too late, but I remember now I encountered a very similar case where "@" was different from "@" because it was a different unicode character. I solved it by hardcoding the Unicode number in the string like "\u0040"

Upvotes: 2

Related Questions