Bug 1327960 - Don't escape the query part of nsSimpleURI. r=valentin.gosu
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Fri, 06 Jan 2017 20:56:14 +0900
changeset 377176 7cafc897f05ed3af0700f6d08b1c0a5d870d5a81
parent 377175 066f1cf5831004dad7a0651fbb869905debd43ea
child 377177 922366c67e721a96dfef08667db57bc1ca1ecedc
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1327960
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1327960 - Don't escape the query part of nsSimpleURI. r=valentin.gosu MozReview-Commit-ID: G5Shb8kYYTx
dom/url/tests/test_url.html
netwerk/base/nsSimpleURI.cpp
--- a/dom/url/tests/test_url.html
+++ b/dom/url/tests/test_url.html
@@ -404,18 +404,19 @@
     is(url.pathname, "path/to/file");
     is(url.search, "?query");
     is(url.hash, "#hash");
 
     // pathname cannot be overwritten.
     url.pathname = "new/path?newquery#newhash";
     is(url.href, "scheme:path/to/file?query#hash");
 
+    // don't escape '#' until we implement a spec-compliant parser.
     url.search = "?newquery#newhash";
-    is(url.href, "scheme:path/to/file?newquery%23newhash#hash");
+    is(url.href, "scheme:path/to/file?newquery#newhash#hash");
 
     // nulls get encoded, whitespace gets stripped
     url = new URL("scheme:pa\0\nth/to/fi\0\nle?qu\0\nery#ha\0\nsh");
     is(url.href, "scheme:pa%00th/to/fi%00le?qu%00ery#ha%00sh");
 
     url.search = "new\0\nquery";
     is(url.href, "scheme:pa%00th/to/fi%00le?new%00%0Aquery#ha%00sh");
     url.hash = "new\0\nhash";
@@ -426,11 +427,16 @@
     url.search = "query";
     is(url.href, "scheme:path?query#hash");
     url.hash = "";
     is(url.href, "scheme:path?query");
     url.hash = "newhash";
     is(url.href, "scheme:path?query#newhash");
     url.search = "";
     is(url.href, "scheme:path#newhash");
+
+    // we don't implement a spec-compliant parser yet.
+    // make sure we are bug compatible with existing implementations.
+    url = new URL("data:text/html,<a href=\"http://example.org/?q\">Link</a>");
+    is(url.href, "data:text/html,<a%20href=\"http://example.org/?q\">Link</a>");
   </script>
 </body>
 </html>
--- a/netwerk/base/nsSimpleURI.cpp
+++ b/netwerk/base/nsSimpleURI.cpp
@@ -808,31 +808,31 @@ nsSimpleURI::GetQuery(nsACString& aQuery
 }
 
 NS_IMETHODIMP
 nsSimpleURI::SetQuery(const nsACString& aQuery)
 {
     NS_ENSURE_STATE(mMutable);
 
     nsAutoCString query;
-    nsresult rv = NS_EscapeURL(aQuery, esc_Query, query, fallible);
+    nsresult rv = NS_EscapeURL(aQuery, esc_OnlyNonASCII, query, fallible);
     if (NS_FAILED(rv)) {
         return rv;
     }
 
     if (query.IsEmpty()) {
-        // Empty string means to remove ref completely.
+        // Empty string means to remove query completely.
         mIsQueryValid = false;
         mQuery.Truncate(); // invariant: mQuery should be empty when it's not valid
         return NS_OK;
     }
 
     mIsQueryValid = true;
 
-    // Gracefully skip initial hash
+    // Gracefully skip initial question mark
     if (query[0] == '?') {
         mQuery = Substring(query, 1);
     } else {
         mQuery = query;
     }
 
     return NS_OK;
 }