-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
url: return valid file: urls fom url.format() #7234
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
`file:` URLs that do not start with `file://` are invalid. Browsers convert `file:/etc/passwd` to `file:///etc/passwd`. This is also what the docs indicate we are doing, but we're not. Fixes: #3361
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -553,7 +553,7 @@ Url.prototype.format = function() { | |
var protocol = this.protocol || ''; | ||
var pathname = this.pathname || ''; | ||
var hash = this.hash || ''; | ||
var host = false; | ||
var host = ''; | ||
var query = ''; | ||
|
||
if (this.host) { | ||
|
@@ -602,13 +602,14 @@ Url.prototype.format = function() { | |
|
||
// only the slashedProtocols get the //. Not mailto:, xmpp:, etc. | ||
// unless they had them to begin with. | ||
if (this.slashes || | ||
(!protocol || slashedProtocol[protocol]) && host !== false) { | ||
host = '//' + (host || ''); | ||
if (pathname && pathname.charCodeAt(0) !== 47/*/*/) | ||
pathname = '/' + pathname; | ||
} else if (!host) { | ||
host = ''; | ||
if (this.slashes || slashedProtocol[protocol]) { | ||
if (this.slashes || host) { | ||
if (pathname && pathname.charCodeAt(0) !== 47/*/*/) | ||
pathname = '/' + pathname; | ||
host = `//${host}`; | ||
} else if (protocol.startsWith('file')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC protocol.length >= 4 &&
protocol.charCodeAt(0) === 102/*f*/ &&
protocol.charCodeAt(1) === 105/*i*/ &&
protocol.charCodeAt(2) === 108/*l*/ &&
protocol.charCodeAt(3) === 101/*e*/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoa, I benchmarked it and yeah, that's quite a performance bump. Will put that change in momentarily... |
||
host = '//'; | ||
} | ||
} | ||
|
||
search = search.replace('#', '%23'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit: last time i checked template strings had noticeable overhead, may need to check again on master now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to string concatenation.