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

Fix panic from update_href in HTMLAnchorElement #11264

Merged
merged 1 commit into from May 19, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -80,8 +80,8 @@ impl HTMLAnchorElement {
}

// https://html.spec.whatwg.org/multipage/#update-href
fn update_href(&self, url: &Url) {
self.upcast::<Element>().set_string_attribute(&atom!("href"), DOMString::from(url.as_str()));
fn update_href(&self, url: DOMString) {
self.upcast::<Element>().set_string_attribute(&atom!("href"), url);
}
}

@@ -160,14 +160,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
// Step 1.
self.reinitialize_url();

// Step 3.
if let Some(url) = self.url.borrow_mut().as_mut() {
if url.scheme() == "javascript" { return; }
// Step 2.
let url = match self.url.borrow_mut().as_mut() {
// Step 3.
Some(ref url) if url.scheme() == "javascript" => return,
None => return,
// Steps 4-5.
UrlHelper::SetHash(url, value);
// Step 6.
self.update_href(url);
}
Some(url) => {
UrlHelper::SetHash(url, value);
DOMString::from(url.as_str())
}
};
// Step 6.
self.update_href(url);
}

// https://html.spec.whatwg.org/multipage/#dom-hyperlink-host
@@ -194,16 +199,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
// Step 1.
self.reinitialize_url();

// Step 3.
if let Some(url) = self.url.borrow_mut().as_mut() {
if url.cannot_be_a_base() {
return;
}
// Step 2.
let url = match self.url.borrow_mut().as_mut() {
// Step 3.
Some(ref url) if url.cannot_be_a_base() => return,
None => return,
// Step 4.
UrlHelper::SetHost(url, value);
// Step 5.
self.update_href(url);
}
Some(url) => {
UrlHelper::SetHost(url, value);
DOMString::from(url.as_str())
}
};
// Step 5.
self.update_href(url);
}

// https://html.spec.whatwg.org/multipage/#dom-hyperlink-hostname
@@ -226,16 +234,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
// Step 1.
self.reinitialize_url();

// Step 3.
if let Some(url) = self.url.borrow_mut().as_mut() {
if url.cannot_be_a_base() {
return;
}
// Step 2.
let url = match self.url.borrow_mut().as_mut() {
// Step 3.
Some(ref url) if url.cannot_be_a_base() => return,
None => return,
// Step 4.
UrlHelper::SetHostname(url, value);
// Step 5.
self.update_href(url);
}
Some(url) => {
UrlHelper::SetHostname(url, value);
DOMString::from(url.as_str())
}
};
// Step 5.
self.update_href(url);
}

// https://html.spec.whatwg.org/multipage/#dom-hyperlink-href
@@ -282,16 +293,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
// Step 1.
self.reinitialize_url();

// Step 3.
if let Some(url) = self.url.borrow_mut().as_mut() {
if url.host().is_none() || url.cannot_be_a_base() {
return;
}
// Step 2.
let url = match self.url.borrow_mut().as_mut() {
// Step 3.
Some(ref url) if url.host().is_none() || url.cannot_be_a_base() => return,
None => return,
// Step 4.
UrlHelper::SetPassword(url, value);
// Step 5.
self.update_href(url);
}
Some(url) => {
UrlHelper::SetPassword(url, value);
DOMString::from(url.as_str())
}
};
// Step 5.
self.update_href(url);
}

// https://html.spec.whatwg.org/multipage/#dom-hyperlink-pathname
@@ -312,14 +326,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
// Step 1.
self.reinitialize_url();

// Step 3.
if let Some(url) = self.url.borrow_mut().as_mut() {
if url.cannot_be_a_base() { return; }
// Step 2.
let url = match self.url.borrow_mut().as_mut() {
// Step 3.
Some(ref url) if url.cannot_be_a_base() => return,
None => return,
// Step 5.
UrlHelper::SetPathname(url, value);
// Step 6.
self.update_href(url);
}
Some(url) => {
UrlHelper::SetPathname(url, value);
DOMString::from(url.as_str())
}
};
// Step 6.
self.update_href(url);
}

// https://html.spec.whatwg.org/multipage/#dom-hyperlink-port
@@ -341,17 +360,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
self.reinitialize_url();

// Step 3.
if let Some(url) = self.url.borrow_mut().as_mut() {
if url.host().is_none() ||
let url = match self.url.borrow_mut().as_mut() {
Some(ref url) if url.host().is_none() ||
url.cannot_be_a_base() ||
url.scheme() == "file" {
return;
}
url.scheme() == "file" => return,
None => return,
// Step 4.
UrlHelper::SetPort(url, value);
// Step 5.
self.update_href(url);
}
Some(url) => {
UrlHelper::SetPort(url, value);
DOMString::from(url.as_str())
}
};
// Step 5.
self.update_href(url);
}

// https://html.spec.whatwg.org/multipage/#dom-hyperlink-protocol
@@ -372,13 +393,17 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
// Step 1.
self.reinitialize_url();

// Step 2.
if let Some(url) = self.url.borrow_mut().as_mut() {
let url = match self.url.borrow_mut().as_mut() {
// Step 2.
None => return,
// Step 3.
UrlHelper::SetProtocol(url, value);
// Step 4.
self.update_href(url);
}
Some(url) => {
UrlHelper::SetProtocol(url, value);
DOMString::from(url.as_str())
}
};
// Step 4.
self.update_href(url);
}

// https://html.spec.whatwg.org/multipage/#dom-hyperlink-search
@@ -399,15 +424,20 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
// Step 1.
self.reinitialize_url();

// Step 3.
if let Some(url) = self.url.borrow_mut().as_mut() {
// Step 2.
let url = match self.url.borrow_mut().as_mut() {
// Step 3.
None => return,
// Steps 4-5.
// TODO add this element's node document character encoding as
// encoding override (as described in the spec)
UrlHelper::SetSearch(url, value);
// Step 6.
self.update_href(url);
}
Some(url) => {
UrlHelper::SetSearch(url, value);
DOMString::from(url.as_str())
}
};
// Step 6.
self.update_href(url);
}

// https://html.spec.whatwg.org/multipage/#dom-hyperlink-username
@@ -428,17 +458,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
// Step 1.
self.reinitialize_url();

// Step 3.
if let Some(url) = self.url.borrow_mut().as_mut() {
if url.host().is_none() || url.cannot_be_a_base() {
return;
}

// Step 2.
let url = match self.url.borrow_mut().as_mut() {
// Step 3.
Some(ref url) if url.host().is_none() || url.cannot_be_a_base() => return,
None => return,
// Step 4.
UrlHelper::SetUsername(url, value);
// Step 5.
self.update_href(url);
}
Some(url) => {
UrlHelper::SetUsername(url, value);
DOMString::from(url.as_str())
}
};
// Step 5.
self.update_href(url);
}

// https://html.spec.whatwg.org/multipage/#dom-hyperlink-href
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.