JavaScript Collation Fail

In JavaScript, the localeCompare method on Strings seems like a great way to properly sort strings, but its not:
localeCompare Javasript method in 4 browsers
Hint: The last line should all look the same. At least I expect Firefox and Opera to agree. You can’t expect much from IE6.

For kicks try out other browsers and post the final sorted list in the comments (hopefully my blog supports unicode).

Updated 2012-05-16: Hilariously a coworker stumbled across this page, so I updated the MDN link as Mozilla had broken it.

This entry was posted in Technology and tagged , , , , , , . Bookmark the permalink.
  • http://www.afruit.com A.Fruit

    Here it is in Safari 3 / Webkit:

  • http://www.afruit.com A.Fruit

    Doh.

    Html got Stripped. Here’s the link to the image:

    http://idisk.mac.com/afruit-Public/safari-js-test.png

  • http://michael.susens-schurter.com/blog/ Michael Schurter

    Just testing out copying and pasting from the test page:

    a,A,ä,æ,q,R,z,Z

    Hm… Safari and Firefox agree. Wonder what IE7 & 8 have to say… I guess IE6 is pretty close to Safari and FF. Seems Opera is the only one completely crazy.

  • http://www.afruit.com A.Fruit

    I’ve been noticing Firefox 3 being closer to Safari, then Firefox 3 is to Firefox 2 –specifically with CSS rendering and stuff. (Which doesn’t have much to do with JS, but it’s just a general thing I’ve observed)

    Webkit advocates do rave about the new JavaScript engine called “Squirrelfish”.

    http://webkit.org/blog/189/announcing-squirrelfish/

    Which brings a reminder about the Dr. Moreau conversations we’ve had.

  • a girl

    IE7: string_list.sort(localesort): a,A,ä,æ,q,R,z,Z

  • Simon

    IE 6 on Windows XP returns the same results as Firefox. Wine is undoubtedly providing a different implementation beneath for localised string comparison then what would be used on a real Windows system, explaining the difference you’ve observed.