Bug 630405 - about pages DOMStorage should be case-insensitive. r=mayhemer a=blocking
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 01 Feb 2011 13:53:04 -0800
changeset 61752 3fab3dca98175177b3976f5d7e884d9285225814
parent 61751 a85d6ae60d96ff4523de57ab315ba72fd96a955d
child 61753 1c4fcf164f1836bf2ce127d26496c4cfd23ff250
push idunknown
push userunknown
push dateunknown
reviewersmayhemer, blocking
bugs630405
milestone2.0b11pre
Bug 630405 - about pages DOMStorage should be case-insensitive. r=mayhemer a=blocking
dom/src/storage/nsDOMStorageDBWrapper.cpp
dom/tests/unit/test_domstorage_aboutpages.js
--- a/dom/src/storage/nsDOMStorageDBWrapper.cpp
+++ b/dom/src/storage/nsDOMStorageDBWrapper.cpp
@@ -354,16 +354,19 @@ nsDOMStorageDBWrapper::CreateDomainScope
   if (domainScope.IsEmpty()) {
     // About pages have an empty host but a valid path.  Since they are handled
     // internally by our own redirector, we can trust them and use path as key.
     PRBool isAboutUrl = PR_FALSE;
     if ((NS_SUCCEEDED(aUri->SchemeIs("about", &isAboutUrl)) && isAboutUrl) ||
         (NS_SUCCEEDED(aUri->SchemeIs("moz-safe-about", &isAboutUrl)) && isAboutUrl)) {
       rv = aUri->GetPath(domainScope);
       NS_ENSURE_SUCCESS(rv, rv);
+      // While the host is always canonicalized to lowercase, the path is not,
+      // thus need to force the casing.
+      ToLowerCase(domainScope);
     }
   }
 
   rv = CreateDomainScopeDBKey(domainScope, aKey);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
--- a/dom/tests/unit/test_domstorage_aboutpages.js
+++ b/dom/tests/unit/test_domstorage_aboutpages.js
@@ -28,16 +28,18 @@ function testURI(aURI)
   do_check_eq(storage.length, 0);
   do_check_eq(storage.getItem("test-item"), null);
 
   testURIWithPrivateBrowsing(aURI);
 
   testURIWithClearCookies(aURI);
 
   testURIWithRejectCookies(aURI);
+
+  testURIWithCasing(aURI);
 }
 
 function testURIWithPrivateBrowsing(aURI) {
   print("Testing with private browsing: " + aURI.spec);
   // Skip test if PB mode is not supported.
   if (!("@mozilla.org/privatebrowsing;1" in Components.classes)) {
     print("Skipped.");
     return;
@@ -104,16 +106,39 @@ function testURIWithRejectCookies(aURI) 
   Services.prefs.setIntPref("network.cookie.lifetimePolicy", 1);
   test_storage();
 
   // Reject.
   Services.prefs.setIntPref("network.cookie.cookieBehavior", 2);
   test_storage();
 }
 
+function testURIWithCasing(aURI) {
+  print("Testing: " + aURI.spec);
+  let storage = getStorageForURI(aURI);
+  storage.setItem("test-item", "test-value");
+  print("Check that our value has been correctly stored.");
+  do_check_eq(storage.length, 1);
+  do_check_eq(storage.key(0), "test-item");
+  do_check_eq(storage.getItem("test-item"), "test-value");
+
+  let ucSpec = aURI.spec.toUpperCase();
+  print("Testing: " + ucSpec);
+  let ucStorage = getStorageForURI(Services.io.newURI(ucSpec, null, null));
+  print("Check that our value is accessible in a case-insensitive way.");
+  do_check_eq(ucStorage.length, 1);
+  do_check_eq(ucStorage.key(0), "test-item");
+  do_check_eq(ucStorage.getItem("test-item"), "test-value");
+
+  print("Check that our value is correctly removed.");
+  storage.removeItem("test-item");
+  do_check_eq(storage.length, 0);
+  do_check_eq(storage.getItem("test-item"), null);
+}
+
 function getStorageForURI(aURI)
 {
   let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"].
                   getService(Components.interfaces.nsIScriptSecurityManager).
                   getCodebasePrincipal(aURI);
   let dsm = Components.classes["@mozilla.org/dom/storagemanager;1"].
             getService(Components.interfaces.nsIDOMStorageManager);
   return dsm.getLocalStorageForPrincipal(principal, "");