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 comments linking to the steps of the specs in the checks on Location setters #25714

Closed
wants to merge 9 commits into from
@@ -165,7 +165,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);
// Step 4: 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::SetHost);
}
Ok(())
}

@@ -184,7 +187,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);
// Step 4: 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(())
}

@@ -216,7 +222,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);
// Step 3: If copyURL's cannot-be-a-base-URL flag is set, terminate these steps.

This comment has been minimized.

Copy link
@gterzian

gterzian Feb 10, 2020

Member

Actually, can we put this comment, and all others, above the Ok(()) branch, because the comments all refer to the steps take when the condition is not met.

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

@@ -229,7 +238,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();
// Step 4: If copyURL cannot have a username/password/port, then return.
// 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(())
}

@@ -242,9 +256,16 @@ 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);
Ok(())
}
// Step 6: If copyURL's scheme is not an HTTP(S) scheme, then terminate these steps.
if let Ok(scheme) = value.split(':').next() {
if scheme.eq_ignore_ascii_case("http") || scheme.eq_ignore_ascii_case("https") {
self.set_url_component(value, UrlHelper::SetProtocol);
}
Ok(())
} else {
Err(Error::Syntax)

This comment has been minimized.

Copy link
@gterzian

gterzian Feb 10, 2020

Member

Here we can put a comment for Step 5, throw a "SyntaxError" DOMException.

}
}

// https://html.spec.whatwg.org/multipage/#dom-location-search
fn GetSearch(&self) -> Fallible<USVString> {
@@ -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.

@@ -3,18 +3,5 @@
[Set data URL frame location.protocol to gopher]
expected: FAIL

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

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

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

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

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

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