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

Implement checks on Location setters #23670

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -140,7 +140,10 @@ impl LocationMethods for Location {
// https://html.spec.whatwg.org/multipage/#dom-location-host
fn SetHost(&self, value: USVString) -> ErrorResult {
self.check_same_origin_domain()?;
self.set_url_component(value, UrlHelper::SetHost);
// If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.

This comment has been minimized.

Copy link
@asajeffrey

asajeffrey Jul 17, 2019

Member

Can you add a comment "Step 4" to this, to make it easy to follow the code wrt the spec? (This applies to the other setters too.) Apart from that, looks great!

if !self.get_url().cannot_be_a_base() {
self.set_url_component(value, UrlHelper::SetHost);
}
Ok(())
}

@@ -159,7 +162,10 @@ impl LocationMethods for Location {
// https://html.spec.whatwg.org/multipage/#dom-location-hostname
fn SetHostname(&self, value: USVString) -> ErrorResult {
self.check_same_origin_domain()?;
self.set_url_component(value, UrlHelper::SetHostname);
// If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.
if !self.get_url().cannot_be_a_base() {
self.set_url_component(value, UrlHelper::SetHostname);
}
Ok(())
}

@@ -191,7 +197,10 @@ impl LocationMethods for Location {
// https://html.spec.whatwg.org/multipage/#dom-location-pathname
fn SetPathname(&self, value: USVString) -> ErrorResult {
self.check_same_origin_domain()?;
self.set_url_component(value, UrlHelper::SetPathname);
// If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.
if !self.get_url().cannot_be_a_base() {
self.set_url_component(value, UrlHelper::SetPathname);
}
Ok(())
}

@@ -204,7 +213,12 @@ impl LocationMethods for Location {
// https://html.spec.whatwg.org/multipage/#dom-location-port
fn SetPort(&self, value: USVString) -> ErrorResult {
self.check_same_origin_domain()?;
self.set_url_component(value, UrlHelper::SetPort);
let url = self.get_url();
// If copyURL cannot have a username/password/port, then return.

This comment has been minimized.

Copy link
@gterzian

This comment has been minimized.

Copy link
@braddunbar
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port
if url.has_host() && !url.cannot_be_a_base() && url.scheme() != "file" {
self.set_url_component(value, UrlHelper::SetPort);
}
Ok(())
}

@@ -217,7 +231,11 @@ impl LocationMethods for Location {
// https://html.spec.whatwg.org/multipage/#dom-location-protocol
fn SetProtocol(&self, value: USVString) -> ErrorResult {
self.check_same_origin_domain()?;
self.set_url_component(value, UrlHelper::SetProtocol);
// If copyURL's scheme is not an HTTP(S) scheme, then terminate these steps.
let scheme = value.split(':').next().unwrap();
if scheme.eq_ignore_ascii_case("http") || scheme.eq_ignore_ascii_case("https") {

This comment has been minimized.

Copy link
@gterzian

gterzian Jul 1, 2019

Member

The spec contains this note:

Because the URL parser ignores multiple consecutive colons, providing a value of "https:" (or even "https::::") is the same as providing a value of "https".

Does this allow for multiple consecutive colons?

If this is currently not tested in the existing tests, you could also consider adding such a testcase.

This comment has been minimized.

Copy link
@braddunbar

braddunbar Jul 1, 2019

Author

Ok, I'll write some tests!

self.set_url_component(value, UrlHelper::SetProtocol);
}
Ok(())
}

@@ -93,6 +93,10 @@ impl ServoUrl {
self.0.scheme()
}

pub fn has_host(&self) -> bool {
self.0.has_host()
}

pub fn is_secure_scheme(&self) -> bool {
let scheme = self.scheme();
scheme == "https" || scheme == "wss"

This file was deleted.

@@ -17,19 +17,3 @@

[Set data URL frame location.protocol to http+x]
expected: FAIL

[Set HTTP URL frame location.protocol to gopher]
expected: FAIL

[Set HTTP URL frame location.protocol to http+x]
expected: FAIL

[Set HTTP URL frame location.protocol to ftp]
expected: FAIL

[Set HTTP URL frame location.protocol to data]
expected: FAIL

[Set HTTP URL frame location.protocol to x]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.