Phantomjs: localeCompare implementation is not following the specification

Created on 11 Feb 2013  路  9Comments  路  Source: ariya/phantomjs

_[email protected] commented:_

Which version of PhantomJS are you using? Tip: run 'phantomjs --version'.
I'm using version 1.8.1

What steps will reproduce the problem?

  1. run phantomjs and in the command line type
  2. 'a'.localeCompare('B')
  3. The result is 1

What is the expected output? What do you see instead?
The expected output is -1
Firefox and Chrome return -1. So they ignore the case sensitivity.
I see 1 in PhantomJs instead of -1

Which operating system are you using?
I'm using Windows 7 x64

Did you use binary PhantomJS or did you compile it from source?
I used binary (.exe)

Please provide any additional information below.
I think PhantomJS needs to ignore the case on the Strings used in the localeCompare() function just like Firefox18 and Chrome24

Disclaimer:
This issue was migrated on 2013-03-15 from the project's former issue tracker on Google Code, Issue #1063.
:star2:   2 people had starred this issue at the time of migration.

Most helpful comment

Hi @Vitallium. Appreciate your work (and all contributors') on this. I'm still seeing this issue even in 2.1.3. Wanted to confirm if something happened with the fix (if it got included or excluded by somehow). Thank you!

All 9 comments

Any update on this ?

Also occurs on phantomjs 1.9.2 on Linux:

PhantomJS 1.9.2 (Linux) Core base tests naturalSortCompare sorts with different casing FAILED
        Expected [ 'AAA', 'BBB', 'aaa', 'bbb' ] to equal [ 'aaa', 'AAA', 'bbb', 'BBB' ].
..
PhantomJS 1.9.2 (Linux) Core base tests naturalSortCompare sorts with umlauts FAILED
        Expected [ 'ah.txt', 'oh.txt', 'uh.txt', '脛h.txt', '脰h.txt', '脺h.txt', '脺h 2.txt', '盲h.txt', '枚h.txt', '眉h.txt' ] to equal [ 'ah.txt', '盲h.txt', '脛h.txt', 'oh.txt', '枚h.txt', '脰h.txt', 'uh.txt', '眉h.txt', '脺h.txt', '脺h 2.txt' ].

This makes it impossible to use unit tests to verify sort orders with continuous integration.

Hi there

Any update on this issue? Anyone know of a workaround?

Thanks!

Also this:

'||'.localeCompare('or')

This returns -1 in Firefox and Chrome, but it returns 1 in PhantomJS 1.9.7.

I am assuming Firefox and Chrome both implements the method according to the standard

:+1:

Our tests fail in PhantomJS because '脜' > 'Z' according to localeCompare.

:+1:

Fixed in 2.0

@Vitallium will the localeCompare fix in 2.0 also address the following problem in 1.9 with combining diacritical marks, or should I make a new issue describing what I'm seeing here? 鈥擳hanks

var accent = "e with acute accent: 茅",  // Acute accented character
    combiningDiacritic = "e with acute accent: e\u0301"; // combining diacritical character
console.log('localeCompare: ' + combiningDiacritic.localeCompare(accent));

Chrome, Firefox output: 'localeCompare: 0'
PhantomJS output: 'localeCompare: -1'

Hi @Vitallium. Appreciate your work (and all contributors') on this. I'm still seeing this issue even in 2.1.3. Wanted to confirm if something happened with the fix (if it got included or excluded by somehow). Thank you!

I'm using v2.1.1 and 'A'.localeCompare('a', undefined, {numeric: true, sensitivity: 'base'}) is giving me -1 instead of 0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Marmeladenbrot picture Marmeladenbrot  路  4Comments

dhilipsiva picture dhilipsiva  路  4Comments

Snowlav picture Snowlav  路  3Comments

olee picture olee  路  4Comments

qaDream77 picture qaDream77  路  4Comments