Bug 386434: Add-ons aren't sorted correctly in Add-ons manager (problem with non-ascii chars). r=dtownsend
authorRégis Caspar <regis.caspar+bz@gmail.com>
Sat, 16 Aug 2008 16:05:07 +0100
changeset 16741 67d16a172040ed20780d837d9664dd682e732565
parent 16740 eee972f86d15cfe0b99ab0b202537834eb5ddac7
child 16742 1b2644a5796687fe75fda474ed2067d9478d982c
push id1285
push userdtownsend@mozilla.com
push dateSat, 16 Aug 2008 15:05:32 +0000
treeherdermozilla-central@67d16a172040 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdtownsend
bugs386434
milestone1.9.1a2pre
Bug 386434: Add-ons aren't sorted correctly in Add-ons manager (problem with non-ascii chars). r=dtownsend
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/src/nsExtensionManager.js.in
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -689,23 +689,19 @@ function displaySearchResults(addons, co
                      gRDF.GetResource(PREFIX_NS_EM + "statusMessage"),
                      gRDF.GetLiteral("true"),
                      true);
     gSearchDS.Assert(labelNode,
                      gRDF.GetResource(PREFIX_NS_EM + "type"),
                      gRDF.GetLiteral("header-recommended"),
                      true);
 
-    // Case insensitive sort
+    // Locale sensitive sort
     function compare(a, b) {
-      if (a.name.toLowerCase() < b.name.toLowerCase())
-        return -1;
-      if (a.name.toLowerCase() > b.name.toLowerCase())
-        return 1;
-      return 0;
+      return String.localeCompare(a.name, b.name);
     }
     addons.sort(compare);
   }
   
   if (addons.length == 0 && (isRecommended || count > 0)) {
     var labelNode = gRDF.GetResource("urn:mozilla:addons:search:status:noresults");
     rootctr.AppendElement(labelNode);
     gSearchDS.Assert(labelNode,
@@ -894,23 +890,19 @@ function rebuildPluginsDS()
   var rootctr = rdfCU.MakeSeq(gPluginsDS, gRDF.GetResource(RDFURI_ITEM_ROOT));
   gPlugins = { };
   
   // Running in a batch stops the template builder from running
   gPluginsDS.beginUpdateBatch();
 
   cleanDataSource(gPluginsDS, rootctr);
 
-  // Case insensitive sort
+  // Locale sensitive sort
   function compare(a, b) {
-    if (a.name.toLowerCase() < b.name.toLowerCase())
-      return -1;
-    if (a.name.toLowerCase() > b.name.toLowerCase())
-      return 1;
-    return 0;
+    return String.localeCompare(a.name, b.name);
   }
   plugins.sort(compare);
 
   for (var i = 0; i < plugins.length; i++) {
     var plugin = plugins[i];
     var name = plugin.name;
     if (!(name in gPlugins))
       gPlugins[name] = { };
--- a/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
+++ b/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
@@ -7984,27 +7984,25 @@ ExtensionsDataSource.prototype = {
     var ordinal = 0;
     while (elements.hasMoreElements()) {
       var item = elements.getNext().QueryInterface(Ci.nsIRDFResource);
       var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
       var itemType = this.getItemProperty(id, "type");
       if (itemType & type) {
         items.push({ item   : item,
                      ordinal: ordinal,
-                     sortkey: this.getItemProperty(id, propertyName).toLowerCase() });
+                     sortkey: this.getItemProperty(id, propertyName) });
         ordinal++;
       }
     }
 
     var direction = isAscending ? 1 : -1;
-    // Case insensitive sort
+    // Locale sensitive sort
     function compare(a, b) {
-        if (a.sortkey < b.sortkey) return (-1 * direction);
-        if (a.sortkey > b.sortkey) return (1 * direction);
-        return 0;
+      return String.localeCompare(a.sortkey, b.sortkey) * direction;
     }
     items.sort(compare);
 
     // Check if there are any changes in the order of the items
     var isDirty = false;
     for (var i = 0; i < items.length; i++) {
       if (items[i].ordinal != i) {
         isDirty = true;