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: URL.port isn't needed anymore Created Feb. 27, 2015, 11:21 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') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/url.js
===================================================================
--- a/lib/url.js
+++ b/lib/url.js
@@ -18,7 +18,7 @@
window.URL = (function()
{
let URL = window.URL || window.webkitURL;
- let URLProperties = ["href", "protocol", "host", "hostname", "port", "pathname", "search"];
+ let URLProperties = ["href", "protocol", "host", "hostname", "pathname", "search"];
kzar 2015/03/02 15:04:13 Do we not need to check the port for a URL anywher
Sebastian Noack 2015/03/02 15:10:37 Not as far as I know. But feel free to double chec
Sebastian Noack 2015/03/02 15:18:21 contentPolicy.js is Firefox-specific code, also it
if (!URL || !URLProperties.every(prop => prop in new URL("about:blank")))
{
@@ -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') | no next file with comments »

Powered by Google App Engine
This is Rietveld