Closed Bug 856115 Opened 11 years ago Closed 5 years ago

String.localeCompare() doesn't work consistently in Linux

Categories

(Core :: JavaScript Engine, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: jennifer.chye, Unassigned)

References

(Depends on 1 open bug)

Details

Attachments

(1 file)

Open the attached file in Firefox which prints out the result of running "'côte'.localeCompare('coté')" in JavaScript. A negative number will be displayed on the page.

On the same page, open the web console and enter "'côte'.localeCompare('coté')".
A positive number will be returned.

Both the page and the web console should have displayed a positive number according to the spec for localeCompare().

This bug was found in Ubuntu 12.04 LTS. It does not occur in Firefox for OS X.
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
We're in the process of switching this stuff over to being done with ICU in a future release (22 quite possibly), so hopefully this will go away then.
Depends on: 724529
It's not guaranteed that this problem will go away.

In the old implementation, the browser installed a comparison function into JavaScript runtimes that was based on string comparison in the operating systems. If the web console behaves differently from browser windows, it probably means that it doesn't get such a comparison function, and therefore uses the primitive string comparison in ECMAScript, which just compares UTF-16 code units.

In the new implementation, it's all based on ICU, but the behavior varies between locales. Those JS runtimes that in the old implementation received a comparison function now receive the browser's default locale. JS runtimes that don't receive the browser's default locale use the operating system's. So, if the browser and the operating system don't agree on the default locale, there may be differences in behavior.

To make sure that you get correct comparisons between 'côte' and 'coté', you can specify French as the locale for localeCompare: "'côte'.localeCompare('coté', 'fr')". This makes the comparison independent of default locales in the new implementation. The old implementation doesn't know the locales argument and simply ignores it.
Assignee: general → nobody

I think this is already fixed as we do use ICU now everywhere. Reopen if needed.

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: