The following gives 0 in Firefox. However it gives -1 in chrome.
var index = "İSTANBUL".toLowerCase().indexOf("is");
console.log(index);
https://jsfiddle.net/81f0yr8w/1/
Chrome puts an extra character when lower casing İ (latin capital letter i with a dot above "\u0130")
"İ".toLocaleLowerCase().length
>2
Is it a normal behaviour?
The toLocaleLowerCase() method does not change the original string. The toLocaleLowerCase() returns the same result as toLowerCase() , except for locales that conflict with the regular Unicode case mappings (such as Turkish).
The toLowerCase() method converts a string to lowercase letters.
The toLowerCase() is an inbuilt function in TypeScript which is used to convert the characters within a string to lowercase.
You can encode the string first then compare it. This will yield the same result in Firefox and Chrome.
// 0 Chrome // 0 Firefox
encodeURIComponent("İSTANBUL".toLowerCase()).indexOf(encodeURIComponent("İS".toLowerCase()))
The fact that Firefox and Chrome handle it differently is strange. But strange is defined by w3c spec here: https://www.w3.org/TR/charmod-norm/#matchingAlgorithm fwiw, you have to lowercase the string first then encode it. They won't match unless they're the same case first.
Found the Firefox Bug and marked duplicate of [812837]. (https://bugzilla.mozilla.org/show_bug.cgi?id=812837) It was reported in 2011 and it's still open. So I guess it's not a priority.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With