Stupid Internet Explorer and stupid IE bugs
I'm placing the finishing touches on a web application I've been writing on and off for the last year. At last, I've reached Internet Explorer bugs, which are usually the last to be fixed. Among several other stupid but documented bugs, I've found one which I couldn't find documented in a shallow search on Google: it seems IE has an algorithm for comparing strings that is different then the one that is used internally when sorting an array of strings.
Take this code, for example, where I have separated the issue:
<html> <body> <script> var x = [ "Zwischenwasse", "Gurtis", "Götzis", "Partenen", "Raggal", "Rietz", "Schnifis", "Vösendorf", "Bludenz", "Galtür" ]; var y = [ [34241, "Zwischenwasse"], [11223, "Gurtis"], [12321, "Götzis"], [12345, "Partenen"], [32454, "Raggal"], [34355, "Rietz"], [43453, "Schnifis"], [42321, "Vösendorf"], [43435, "Bludenz"], [43222, "Galtür"] ]; x.sort(); document.write(x); document.write("<br/>"); var sorted = y.sort(function(a,b){ return a[1] > b[1]; }); for (var i=0;i<sorted.length;i++) { document.write(sorted[i][1]+ ","); } </script> </html>
The value which will be written in Internet Explorer when running this html document is:
Bludenz,Galtür,Gurtis,Götzis,Partenen,Raggal,Rietz,Schnifis,Vösendorf,Zwischenwasse Bludenz,Galtür,Zwischenwasse,Gurtis,Götzis,Partenen,Raggal,Rietz,Schnifis,Vösendorf,
Needless to say, in Firefox both lines will be the same, displayed in the proper order. On a side note, while I'm bashing Internet Explorer, let me just say that Internet Explorer 8 is a broken piece of software, at least on the side that I'm concerned. The developer tools are really buggy and tend to block the browser for even trivial operations (that is, when it doesn't crash it completely).
Update: apparently my mind is clouded with too much Python (I admit that Javascript is not a language that I use often). The problem is that the inline function used as sorting discriminator should return numeric values of -1, 0, 1, like this:
var sorted = y.sort(function(a,b){ if (a[1] > b[1]){ return 1; } if (a[1] < b[1]){ return -1 } return 0; });
Previous: Workingenv, setuptools and svn 1.5 redux