Skip to content
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

Add tests for URL setters #2830

Merged
merged 2 commits into from
May 11, 2016
Merged

Add tests for URL setters #2830

merged 2 commits into from
May 11, 2016

Conversation

SimonSapin
Copy link
Contributor

A lot of them fail in browsers, but I believe they’re should pass in a spec-conforming implementation. (With a few exceptions noted in comments.)

CC @domenic

@wpt-pr-bot
Copy link
Collaborator

Reviewers for this pull request are: @Sebmaster, @domenic, @frewsxcv, @mikewest, @rubys, @sideshowbarker, @smola, @tomalec, @xiaojunwu, and @zcorpan.

@hoppipolla-critic-bot
Copy link

Critic review: https://critic.hoppipolla.co.uk/r/6391

This is an external review system which you may optionally use for the code review of your pull request.

In order to help critic track your changes, please do not make in-place history rewrites (e.g. via git rebase -i or git commit --amend) when updating this pull request.

@zcorpan
Copy link
Member

zcorpan commented Apr 14, 2016

The deviations are only for whatwg/url#104 right?

@SimonSapin
Copy link
Contributor Author

That and whatwg/url#113 and whatwg/url#114.

for (var attr in test_case.expected) {
assert_equals(url[attr], test_case.expected[attr])
}
}, "Setting <" + test_case.href + ">." + attr + " = '" + test_case.new_value + "' " + test_case.comment)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't append comment if it's undefined

@domenic
Copy link
Member

domenic commented Apr 15, 2016

I ran this against https://github.com/jsdom/whatwg-url and got the following failures:

<a://example.net>.protocol = "bC0+-."
<http://example.net>.protocol = "b" Spec deviation: from special scheme to not is not problematic. https://github.com/whatwg/url/issues/104
<ssh://me@example.net>.protocol = "http" Spec deviation: from non-special scheme with a host to special is not problematic. https://github.com/whatwg/url/issues/104
<http://example.net:8080>.host = "example.com:" Port number is removed if empty in the new value: https://github.com/whatwg/url/pull/113
<http://example.net>.host = "" The empty host is not valid for special schemes
<view-source+http://example.net/path>.host = "example.com\stuff" \ is not a delimiter for non-special schemes, and it’s invalid in a domain
<http://example.net/path>.host = "example.com:65536" Port numbers are 16 bit integers, overflowing is an error. Hostname is still set, though.
<http://example.net>.hostname = "" The empty host is not valid for special schemes
<view-source+http://example.net/path>.hostname = "example.com\stuff" \ is not a delimiter for non-special schemes, and it’s invalid in a domain
<http://example.net:8080>.port = "" Port number is removed if empty in the new value: https://github.com/whatwg/url/pull/113
<http://example.net:8080/path>.port = "65536" Port numbers are 16 bit integers, overflowing is an error

Some of these may be bugs in jsdom/whatwg-url; after all, we didn't have tests. Some of them are noted as spect violations already. But some of them seem like potential test bugs. For example, I cannot find any spec support for

<http://example.net:8080>.port = "" Port number is removed if empty in the new value

@domenic
Copy link
Member

domenic commented Apr 15, 2016

A bunch of tests were fixed by adding a try/catch around the setter line. It seems like the test format does not encode cases where the setter throws, instead just leaving them as expected = result of parsing href. I think it should instead have an explicit "expected": "failure" format similar to urltestdata.json.

domenic added a commit to jsdom/whatwg-url that referenced this pull request Apr 15, 2016
@domenic
Copy link
Member

domenic commented Apr 15, 2016

OK, I found one bug in our scheme parsing state. The remaining list of things where either jsdom/whatwg-url has a bug or the spec is not matched, accounting for the failure to distinguish throwing setters from no-ops as mentioned above, is these four:

<http://example.net>.protocol = "b" Spec deviation: from special scheme to not is not problematic. https://github.com/whatwg/url/issues/104
<ssh://me@example.net>.protocol = "http" Spec deviation: from non-special scheme with a host to special is not problematic. https://github.com/whatwg/url/issues/104
<http://example.net:8080>.host = "example.com:" Port number is removed if empty in the new value: https://github.com/whatwg/url/pull/113
<http://example.net:8080>.port = "" Port number is removed if empty in the new value: https://github.com/whatwg/url/pull/113

I count two spec deviations plus the problem I mentioned above where I can't find where in the spec the port number is removed if empty is the new value.

@SimonSapin
Copy link
Contributor Author

Re undefined comment and shadowing attr: done.

The url.port = "" case is also a deliberate spec deviation per whatwg/url#113. I’ve marked it as such. But maybe it’s better for this PR to not include any spec deviation, and update tests later if the spec changes?

Re exceptions, none of the setters (except href which is not tested here) throw per https://url.spec.whatwg.org/#api if I’m reading correctly. (Compare "If parsedURL is failure, throw a TypeError exception." in the href setter v.s. the lack of such a step in other setters, meaning a parser failure there is silently ignored.) So an implementation throwing should make the test fail. (Unless of course the spec is wrong and needs to be changed.)

@domenic
Copy link
Member

domenic commented Apr 16, 2016

But maybe it’s better for this PR to not include any spec deviation, and update tests later if the spec changes?

Yeah, probably; we could just wait to land this until the spec gets updated, of course.

So an implementation throwing should make the test fail.

Oh, very interesting. @Sebmaster any reason we implemented this as throws?

@Sebmaster
Copy link
Contributor

Sebmaster commented Apr 16, 2016

Seems like we've been doing this wrong since jsdom/whatwg-url#36, since we started using the basicURLParse helper in setters which throws 😕

@SimonSapin
Copy link
Contributor Author

FWIW https://url.spec.whatwg.org/#concept-basic-url-parser returns a value that is either an URL record or "failure". Algorithms in this spec don’t have a concept of exceptions or stack unwinding, error handling is based on explicit "return values".

SimonSapin added a commit that referenced this pull request Apr 17, 2016
@SimonSapin
Copy link
Contributor Author

But maybe it’s better for this PR to not include any spec deviation?

I’ve added a separate commit to do this.

@domenic
Copy link
Member

domenic commented Apr 26, 2016

This LGTM then with the for-now revert. Will let you merge if you want to do any last-minute touchups or similar.

I wish we'd caught the throw vs. silent failure issue when designing the URL API. Loud failure would have been much nicer for authors. Oh well.

A lot of them fail in browsers, but I believe they’re should pass
in a spec-conforming implementation.
(With a few exceptions noted in comments.)
See #2830 (comment).

This can be un-reverted when the following are fixed in the spec:

- whatwg/url#113
- whatwg/url#104
@domenic domenic merged commit 4ec7252 into master May 11, 2016
@domenic domenic deleted the url-setters branch May 11, 2016 03:46
domenic added a commit to jsdom/whatwg-url that referenced this pull request May 11, 2016
As discussed in web-platform-tests/wpt#2830 (comment). This makes the setter tests pass (by having most of them ignore invalid input instead of throwing). It should also make parsing failures during construction throw correctly; previously they were checking a nonexistant urlRecord.failure property.

This changes the public API by making the URL-record-returning functions return either a URL record or the string "failure", instead of returning either a URL record or throwing.
domenic added a commit to jsdom/whatwg-url that referenced this pull request May 11, 2016
As discussed in web-platform-tests/wpt#2830 (comment). This makes the setter tests pass (by having most of them ignore invalid input instead of throwing). It should also make parsing failures during construction throw correctly; previously they were checking a nonexistant urlRecord.failure property.

This changes the public API by making the URL-record-returning functions return either a URL record or the string "failure", instead of returning either a URL record or throwing.
domenic added a commit to jsdom/whatwg-url that referenced this pull request May 28, 2016
As discussed in web-platform-tests/wpt#2830 (comment). This makes the setter tests pass (by having most of them ignore invalid input instead of throwing). It should also make parsing failures during construction throw correctly; previously they were checking a nonexistant urlRecord.failure property.

This changes the public API by making the URL-record-returning functions return either a URL record or the string "failure", instead of returning either a URL record or throwing.
arronei pushed a commit to arronei/web-platform-tests that referenced this pull request Jun 14, 2016
See web-platform-tests#2830 (comment).

This can be un-reverted when the following are fixed in the spec:

- whatwg/url#113
- whatwg/url#104
ivanzr pushed a commit to ivanzr/web-platform-tests that referenced this pull request Jun 29, 2016
See web-platform-tests#2830 (comment).

This can be un-reverted when the following are fixed in the spec:

- whatwg/url#113
- whatwg/url#104
@annevk annevk mentioned this pull request Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants