handle query parameters and full-string queries as specified in the updated safebrowsing protocol. b=395377, r=tony, a=mconnor
authordcamp@mozilla.com
Mon, 01 Oct 2007 16:53:53 -0700
changeset 6503 10a863b2346437c31b3adc021f9558757713b91f
parent 6502 22e53a328d68693d13181b737e6ed9f5a88d5ca4
child 6504 8440f0effe69801bbcda2d9352f1b64bcda0e948
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstony, mconnor
bugs395377
milestone1.9a9pre
handle query parameters and full-string queries as specified in the updated safebrowsing protocol. b=395377, r=tony, a=mconnor
toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
toolkit/components/url-classifier/src/nsUrlClassifierUtils.cpp
toolkit/components/url-classifier/tests/unit/test_dbservice.js
--- a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
@@ -642,21 +642,22 @@ nsUrlClassifierDBServiceWorker::GetLooku
   spec.EndReading(end);
 
   iter = begin;
   if (!FindCharInReadable('/', iter, end)) {
     return NS_OK;
   }
 
   const nsCSubstring& host = Substring(begin, iter++);
-  const nsCSubstring& path = Substring(iter, end);
+  nsCAutoString path;
+  path.Assign(Substring(iter, end));
 
   /**
    * From the protocol doc:
-   * For the hostname, the client will  try at most 5 different strings.  They
+   * For the hostname, the client will try at most 5 different strings.  They
    * are:
    * a) The exact hostname of the url
    * b) The 4 hostnames formed by starting with the last 5 components and
    *    successivly removing the leading component.  The top-level component
    *    can be skipped.
    */
   nsCStringArray hosts;
   hosts.AppendCString(host);
@@ -672,59 +673,57 @@ nsUrlClassifierDBServiceWorker::GetLooku
       hosts.AppendCString(Substring(end, iter));
     }
     end = begin;
     host.BeginReading(begin);
   }
 
   /**
    * From the protocol doc:
-   * For the path, the client will also try at most 5 different strings.
+   * For the path, the client will also try at most 6 different strings.
    * They are:
-   * a) the exact path of the url
-   * b) the 4 paths formed by starting at the root (/) and
+   * a) the exact path of the url, including query parameters
+   * b) the exact path of the url, without query parameters
+   * c) the 4 paths formed by starting at the root (/) and
    *    successively appending path components, including a trailing
    *    slash.  This behavior should only extend up to the next-to-last
    *    path component, that is, a trailing slash should never be
    *    appended that was not present in the original url.
    */
   nsCStringArray paths;
   paths.AppendCString(path);
 
+  path.BeginReading(iter);
+  path.EndReading(end);
+  if (FindCharInReadable('?', iter, end)) {
+    path.BeginReading(begin);
+    path = Substring(begin, iter);
+    paths.AppendCString(path);
+  }
+
   numComponents = 0;
   path.BeginReading(begin);
   path.EndReading(end);
   iter = begin;
   while (FindCharInReadable('/', iter, end) &&
          numComponents < MAX_PATH_COMPONENTS) {
     iter++;
     paths.AppendCString(Substring(begin, iter));
     numComponents++;
   }
 
-  /**
-   * "In addition to these, the client should look up the exact host
-   * and exact path, with a trailing '$' appended." */
-  nsCAutoString key;
-  key.Assign(spec);
-  key.Append('$');
-  LOG(("Chking %s", key.get()));
-
-  nsUrlClassifierHash* hash = fragments.AppendElement();
-  if (!hash) return NS_ERROR_OUT_OF_MEMORY;
-  hash->FromPlaintext(key, mCryptoHash);
-
   for (int hostIndex = 0; hostIndex < hosts.Count(); hostIndex++) {
     for (int pathIndex = 0; pathIndex < paths.Count(); pathIndex++) {
+      nsCAutoString key;
       key.Assign(*hosts[hostIndex]);
       key.Append('/');
       key.Append(*paths[pathIndex]);
       LOG(("Chking %s", key.get()));
 
-      hash = fragments.AppendElement();
+      nsUrlClassifierHash* hash = fragments.AppendElement();
       if (!hash) return NS_ERROR_OUT_OF_MEMORY;
       hash->FromPlaintext(key, mCryptoHash);
     }
   }
 
   return NS_OK;
 }
 
--- a/toolkit/components/url-classifier/src/nsUrlClassifierUtils.cpp
+++ b/toolkit/components/url-classifier/src/nsUrlClassifierUtils.cpp
@@ -132,25 +132,21 @@ nsUrlClassifierUtils::GetKeyForURI(nsIUR
 
   nsresult rv = CanonicalizeHostname(host, _retval);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCAutoString path;
   rv = innerURI->GetPath(path);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // strip out anchors and query parameters
+  // strip out anchors
   PRInt32 ref = path.FindChar('#');
   if (ref != kNotFound)
     path.SetLength(ref);
 
-  ref = path.FindChar('?');
-  if (ref != kNotFound)
-    path.SetLength(ref);
-
   nsCAutoString temp;
   rv = CanonicalizePath(path, temp);
   NS_ENSURE_SUCCESS(rv, rv);
 
   _retval.Append(temp);
 
   return NS_OK;
 }
--- a/toolkit/components/url-classifier/tests/unit/test_dbservice.js
+++ b/toolkit/components/url-classifier/tests/unit/test_dbservice.js
@@ -8,17 +8,18 @@ var chunk1Urls = [
   "test.com/foo/bar",
   "foo.bar.com/a/b/c"
 ];
 var chunk1 = chunk1Urls.join("\n");
 
 var chunk2Urls = [
   "blah.com/a",
   "baz.com/",
-  "255.255.0.1/"
+  "255.255.0.1/",
+  "www.foo.com/test2?param=1"
 ];
 var chunk2 = chunk2Urls.join("\n");
 
 var chunk3Urls = [
   "test.com/a",
   "foo.bar.com/a",
   "blah.com/a",
   ];