Bug 1288482 - Backout bug 1042347. r=mcmanus
authorValentin Gosu <valentin.gosu@gmail.com>
Sun, 24 Jul 2016 23:35:12 +0200
changeset 332553 405ec13645471f1e72312be99220eb66eaf2af5d
parent 332552 5785e6e80c6696b6e941edcbc06583864d95ae95
child 332554 59ddf661a7ee6f05e59c296981f125f49a7478ae
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1288482, 1042347
milestone50.0a1
Bug 1288482 - Backout bug 1042347. r=mcmanus MozReview-Commit-ID: J3LmMfQ854V
netwerk/base/nsURLHelper.cpp
netwerk/test/unit/test_standardurl.js
testing/web-platform/meta/url/a-element-xhtml.xhtml.ini
testing/web-platform/meta/url/a-element.html.ini
testing/web-platform/meta/url/url-constructor.html.ini
--- a/netwerk/base/nsURLHelper.cpp
+++ b/netwerk/base/nsURLHelper.cpp
@@ -234,45 +234,61 @@ net_CoalesceDirs(netCoalesceFlags flags,
     /* Stolen from the old netlib's mkparse.c.
      *
      * modifies a url of the form   /foo/../foo1  ->  /foo1
      *                       and    /foo/./foo1   ->  /foo/foo1
      *                       and    /foo/foo1/..  ->  /foo/
      */
     char *fwdPtr = path;
     char *urlPtr = path;
-    char *endPath = path;
+    char *lastslash = path;
     uint32_t traversal = 0;
     uint32_t special_ftp_len = 0;
 
     /* Remember if this url is a special ftp one: */
     if (flags & NET_COALESCE_DOUBLE_SLASH_IS_ROOT) 
     {
        /* some schemes (for example ftp) have the speciality that 
           the path can begin // or /%2F to mark the root of the 
           servers filesystem, a simple / only marks the root relative 
           to the user loging in. We remember the length of the marker */
         if (nsCRT::strncasecmp(path,"/%2F",4) == 0)
             special_ftp_len = 4;
         else if (nsCRT::strncmp(path,"//",2) == 0 )
             special_ftp_len = 2; 
     }
 
-    /* find the end of the path - places the cursor on \0, ? or # */
-    for(; (*fwdPtr != '\0') &&
-            (*fwdPtr != '?') &&
+    /* find the last slash before # or ? */
+    for(; (*fwdPtr != '\0') && 
+            (*fwdPtr != '?') && 
             (*fwdPtr != '#'); ++fwdPtr)
     {
     }
 
-    endPath = fwdPtr;
+    /* found nothing, but go back one only */
+    /* if there is something to go back to */
+    if (fwdPtr != path && *fwdPtr == '\0')
+    {
+        --fwdPtr;
+    }
+
+    /* search the slash */
+    for(; (fwdPtr != path) && 
+            (*fwdPtr != '/'); --fwdPtr)
+    {
+    }
+    lastslash = fwdPtr;
     fwdPtr = path;
 
     /* replace all %2E or %2e with . in the path */
-    for(; fwdPtr != endPath; ++fwdPtr)
+    /* but stop at lastchar if non null */
+    for(; (*fwdPtr != '\0') && 
+            (*fwdPtr != '?') && 
+            (*fwdPtr != '#') &&
+            (*lastslash == '\0' || fwdPtr != lastslash); ++fwdPtr)
     {
         if (*fwdPtr == '%' && *(fwdPtr+1) == '2' && 
             (*(fwdPtr+2) == 'E' || *(fwdPtr+2) == 'e'))
         {
             *urlPtr++ = '.';
             ++fwdPtr;
             ++fwdPtr;
         } 
--- a/netwerk/test/unit/test_standardurl.js
+++ b/netwerk/test/unit/test_standardurl.js
@@ -296,42 +296,16 @@ add_test(function test_hugeStringThrows(
     Assert.throws(() => url[prop] = hugeString,
                   /NS_ERROR_MALFORMED_URI/,
                   `Passing a huge string to "${prop}" should throw`);
   }
 
   run_next_test();
 });
 
-add_test(function test_pathPercentEncodedDot()
-{
-  var url = stringToURL("http://example.com/%2eX/X%2e/%2eX");
-  do_check_eq(url.spec, "http://example.com/.X/X./.X");
-
-  url = stringToURL("http://example.com/hello/%2e%2E/%2e");
-  do_check_eq(url.spec, "http://example.com/");
-
-  url = stringToURL("http://example.com/hello/%2e%2E/%");
-  do_check_eq(url.spec, "http://example.com/%");
-
-  url = stringToURL("http://example.com/hello/%2e%2E/%2");
-  do_check_eq(url.spec, "http://example.com/%2");
-
-  url = stringToURL("http://example.com/hello/%2e%2E/%#");
-  do_check_eq(url.spec, "http://example.com/%#");
-
-  url = stringToURL("http://example.com/hello/%2e%2E/%2?");
-  do_check_eq(url.spec, "http://example.com/%2?");
-
-  url = stringToURL("http://example.com/hello/%2e/");
-  do_check_eq(url.spec, "http://example.com/hello/");
-
-  run_next_test();
-});
-
 add_test(function test_filterWhitespace()
 {
   var url = stringToURL(" \r\n\th\nt\rt\tp://ex\r\n\tample.com/path\r\n\t/\r\n\tto the/fil\r\n\te.e\r\n\txt?que\r\n\try#ha\r\n\tsh \r\n\t ");
   do_check_eq(url.spec, "http://example.com/path/to%20the/file.ext?query#hash");
   run_next_test();
 });
 
 add_test(function test_backslashReplacement()
--- a/testing/web-platform/meta/url/a-element-xhtml.xhtml.ini
+++ b/testing/web-platform/meta/url/a-element-xhtml.xhtml.ini
@@ -127,16 +127,19 @@
     expected: FAIL
 
   [Parsing: <file://test> against <file:///tmp/mock/path>]
     expected: FAIL
 
   [Parsing: <http://www.google.com/foo?bar=baz# »> against <about:blank>]
     expected: FAIL
 
+  [Parsing: <http://example.com/foo/%2e> against <about:blank>]
+    expected: FAIL
+
   [Parsing: <data:test# »> against <about:blank>]
     expected: FAIL
 
   [Parsing: <http://[www.google.com\]/> against <about:blank>]
     expected: FAIL
 
   [Parsing: <http://192.0x00A80001> against <about:blank>]
     expected: FAIL
@@ -430,8 +433,13 @@
     expected: FAIL
 
   [Parsing: <sc::a@example.net> against <about:blank>]
     expected: FAIL
 
   [Parsing: <http:> against <https://example.org/foo/bar>]
     expected: FAIL
 
+  [Parsing: <http://example.com/foo/%2e%2> against <about:blank>]
+    expected: FAIL
+
+  [Parsing: <http://example.com/foo/%2e./%2e%2e/.%2e/%2e.bar> against <about:blank>]
+    expected: FAIL
--- a/testing/web-platform/meta/url/a-element.html.ini
+++ b/testing/web-platform/meta/url/a-element.html.ini
@@ -118,16 +118,19 @@
     expected: FAIL
 
   [Parsing: </\\server/file> against <file:///tmp/mock/path>]
     expected: FAIL
 
   [Parsing: <file://test> against <file:///tmp/mock/path>]
     expected: FAIL
 
+  [Parsing: <http://example.com/foo/%2e> against <about:blank>]
+    expected: FAIL
+
   [Parsing: <data:test# »> against <about:blank>]
     expected: FAIL
 
   [Parsing: <http://[www.google.com\]/> against <about:blank>]
     expected: FAIL
 
   [Parsing: <http://192.0x00A80001> against <about:blank>]
     expected: FAIL
@@ -439,8 +442,13 @@
     expected: FAIL
 
   [Parsing: <sc::a@example.net> against <about:blank>]
     expected: FAIL
 
   [Parsing: <http:> against <https://example.org/foo/bar>]
     expected: FAIL
 
+  [Parsing: <http://example.com/foo/%2e%2> against <about:blank>]
+    expected: FAIL
+
+  [Parsing: <http://example.com/foo/%2e./%2e%2e/.%2e/%2e.bar> against <about:blank>]
+    expected: FAIL
--- a/testing/web-platform/meta/url/url-constructor.html.ini
+++ b/testing/web-platform/meta/url/url-constructor.html.ini
@@ -70,16 +70,19 @@
     expected: FAIL
 
   [Parsing: <file://test> against <file:///tmp/mock/path>]
     expected: FAIL
 
   [Parsing: <http://www.google.com/foo?bar=baz# »> against <about:blank>]
     expected: FAIL
 
+  [Parsing: <http://example.com/foo/%2e> against <about:blank>]
+    expected: FAIL
+
   [Parsing: <data:test# »> against <about:blank>]
     expected: FAIL
 
   [Parsing: <http://192.0x00A80001> against <about:blank>]
     expected: FAIL
 
   [Parsing: <http://user:pass@/> against <about:blank>]
     expected: FAIL
@@ -274,8 +277,13 @@
     expected: FAIL
 
   [Parsing: <http://f:999999/c> against <http://example.org/foo/bar>]
     expected: FAIL
 
   [Parsing: <http://www/foo%2Ehtml> against <about:blank>]
     expected: FAIL
 
+  [Parsing: <http://example.com/foo/%2e%2> against <about:blank>]
+    expected: FAIL
+
+  [Parsing: <http://example.com/foo/%2e./%2e%2e/.%2e/%2e.bar> against <about:blank>]
+    expected: FAIL