Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/url.js

Issue 5919468974768128: Issue 2062 - Preserve trailing question mark when converting URL into string (Closed)
Patch Set: Created Feb. 27, 2015, 8:05 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | qunit/tests/url.js » ('j') | qunit/tests/url.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/url.js
===================================================================
--- a/lib/url.js
+++ b/lib/url.js
@@ -85,8 +85,8 @@
exports.extractHostFromFrame = extractHostFromFrame;
/**
- * Converts a URL object into a string. For HTTP(S) URLs the hash and
- * auth crendetials are stripped, and the hostname gets IDN-decoded.
+ * Converts a URL object into a string. For HTTP(S) URLs
+ * the hostname gets IDN-decoded and the hash is stripped.
*
* @param {URL} [url]
* @return {string}
@@ -94,14 +94,22 @@
function stringifyURL(url)
{
let protocol = url.protocol;
- if (protocol != "http:" && protocol != "https:")
- return url.href;
+ let href = url.href;
- let host = getDecodedHostname(url);
- if (url.port)
- host += ":" + url.port;
- return protocol + "//" + host + url.pathname + url.search;
+ if (protocol == "http:" || protocol == "https:")
+ {
+ let hostname = url.hostname;
+ if (hostname.indexOf("xn--") != -1)
+ href = href.replace(hostname, punycode.toUnicode(hostname));
+
+ let hash = href.indexOf("#");
+ if (hash != -1)
+ href = href.substr(0, hash);
+ }
+
+ return href;
}
+
exports.stringifyURL = stringifyURL;
function isDomain(hostname)
« no previous file with comments | « no previous file | qunit/tests/url.js » ('j') | qunit/tests/url.js » ('J')

Powered by Google App Engine
This is Rietveld