-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: adding WHATWG URL support #7448
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const url = require('url'); | ||
const v8 = require('v8'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: 'one two three four five'.split(' '), | ||
method: ['old', 'new'], | ||
n: [25e4] | ||
}); | ||
|
||
function useOld(n, input) { | ||
// Force-optimize url.parse() so that the benchmark doesn't get | ||
// disrupted by the optimizer kicking in halfway through. | ||
url.parse(input); | ||
v8.setFlagsFromString('--allow_natives_syntax'); | ||
eval('%OptimizeFunctionOnNextCall(url.parse)'); | ||
|
||
bench.start(); | ||
for (var i = 0; i < n; i += 1) | ||
url.parse(input); | ||
bench.end(n); | ||
} | ||
|
||
function useNew(n, input) { | ||
bench.start(); | ||
for (var i = 0; i < n; i += 1) | ||
new url.URL(input); | ||
bench.end(n); | ||
} | ||
|
||
function main(conf) { | ||
const type = conf.type; | ||
const n = conf.n | 0; | ||
const method = conf.method; | ||
|
||
var inputs = { | ||
one: 'http://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj', | ||
two: 'http://blog.nodejs.org/', | ||
three: 'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en', | ||
four: 'javascript:alert("node is awesome");', | ||
//five: 'some.ran/dom/url.thing?oh=yes#whoo', | ||
five: 'https://user:pass@example.com/', | ||
}; | ||
var input = inputs[type] || ''; | ||
|
||
switch (method) { | ||
case 'old': | ||
useOld(n, input); | ||
break; | ||
case 'new': | ||
useNew(n, input); | ||
break; | ||
default: | ||
throw new Error('Unknown method'); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why this is not used?
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.
The WHATWG URL parser algorithm does not support URLs that do not have a scheme prefix without a base URL so the
five
case is always an error.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.
Perhaps use
http://
(literally, without any domain) as default base URL for the parser?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.
The initial goal to impl the WHATWG parsing spec as is without introducing
any additional default behavior. As such, since that spec does not assume a
default, neither does this impl. I do believe it may be worthwhile adding
an escape hatch for extended behaviors with the understanding that those
are nonstandard.
On Jul 20, 2016 10:09 AM, "Ingvar Stepanyan" notifications@github.com
wrote:
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.
No, base URLs should be explicit. You shouldn't accept relative URLs as absolute ones. They should error.
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.
I meant having default base URL for test purposes only (so that we could check parsing of relative URLs with given base).
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.
The standard tests cover this well already. This particular case is in the benchmarks, which currently do not cover base URLs as I wanted to keep the benchmark as close to the existing
url.parse
benchmark as possible.