mirror of
https://github.com/servo/servo.git
synced 2025-07-29 10:10:34 +01:00
Fix panic from update_href in HTMLAnchorElement
This commit is contained in:
parent
dea610986d
commit
deadfa65cc
1 changed files with 106 additions and 74 deletions
|
@ -80,8 +80,8 @@ impl HTMLAnchorElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#update-href
|
// https://html.spec.whatwg.org/multipage/#update-href
|
||||||
fn update_href(&self, url: &Url) {
|
fn update_href(&self, url: DOMString) {
|
||||||
self.upcast::<Element>().set_string_attribute(&atom!("href"), DOMString::from(url.as_str()));
|
self.upcast::<Element>().set_string_attribute(&atom!("href"), url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,14 +160,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
self.reinitialize_url();
|
self.reinitialize_url();
|
||||||
|
|
||||||
// Step 3.
|
// Step 2.
|
||||||
if let Some(url) = self.url.borrow_mut().as_mut() {
|
let url = match self.url.borrow_mut().as_mut() {
|
||||||
if url.scheme() == "javascript" { return; }
|
// Step 3.
|
||||||
|
Some(ref url) if url.scheme() == "javascript" => return,
|
||||||
|
None => return,
|
||||||
// Steps 4-5.
|
// Steps 4-5.
|
||||||
UrlHelper::SetHash(url, value);
|
Some(url) => {
|
||||||
// Step 6.
|
UrlHelper::SetHash(url, value);
|
||||||
self.update_href(url);
|
DOMString::from(url.as_str())
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// Step 6.
|
||||||
|
self.update_href(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-host
|
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-host
|
||||||
|
@ -194,16 +199,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
self.reinitialize_url();
|
self.reinitialize_url();
|
||||||
|
|
||||||
// Step 3.
|
// Step 2.
|
||||||
if let Some(url) = self.url.borrow_mut().as_mut() {
|
let url = match self.url.borrow_mut().as_mut() {
|
||||||
if url.cannot_be_a_base() {
|
// Step 3.
|
||||||
return;
|
Some(ref url) if url.cannot_be_a_base() => return,
|
||||||
}
|
None => return,
|
||||||
// Step 4.
|
// Step 4.
|
||||||
UrlHelper::SetHost(url, value);
|
Some(url) => {
|
||||||
// Step 5.
|
UrlHelper::SetHost(url, value);
|
||||||
self.update_href(url);
|
DOMString::from(url.as_str())
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// Step 5.
|
||||||
|
self.update_href(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-hostname
|
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-hostname
|
||||||
|
@ -226,16 +234,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
self.reinitialize_url();
|
self.reinitialize_url();
|
||||||
|
|
||||||
// Step 3.
|
// Step 2.
|
||||||
if let Some(url) = self.url.borrow_mut().as_mut() {
|
let url = match self.url.borrow_mut().as_mut() {
|
||||||
if url.cannot_be_a_base() {
|
// Step 3.
|
||||||
return;
|
Some(ref url) if url.cannot_be_a_base() => return,
|
||||||
}
|
None => return,
|
||||||
// Step 4.
|
// Step 4.
|
||||||
UrlHelper::SetHostname(url, value);
|
Some(url) => {
|
||||||
// Step 5.
|
UrlHelper::SetHostname(url, value);
|
||||||
self.update_href(url);
|
DOMString::from(url.as_str())
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// Step 5.
|
||||||
|
self.update_href(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-href
|
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-href
|
||||||
|
@ -282,16 +293,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
self.reinitialize_url();
|
self.reinitialize_url();
|
||||||
|
|
||||||
// Step 3.
|
// Step 2.
|
||||||
if let Some(url) = self.url.borrow_mut().as_mut() {
|
let url = match self.url.borrow_mut().as_mut() {
|
||||||
if url.host().is_none() || url.cannot_be_a_base() {
|
// Step 3.
|
||||||
return;
|
Some(ref url) if url.host().is_none() || url.cannot_be_a_base() => return,
|
||||||
}
|
None => return,
|
||||||
// Step 4.
|
// Step 4.
|
||||||
UrlHelper::SetPassword(url, value);
|
Some(url) => {
|
||||||
// Step 5.
|
UrlHelper::SetPassword(url, value);
|
||||||
self.update_href(url);
|
DOMString::from(url.as_str())
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// Step 5.
|
||||||
|
self.update_href(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-pathname
|
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-pathname
|
||||||
|
@ -312,14 +326,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
self.reinitialize_url();
|
self.reinitialize_url();
|
||||||
|
|
||||||
// Step 3.
|
// Step 2.
|
||||||
if let Some(url) = self.url.borrow_mut().as_mut() {
|
let url = match self.url.borrow_mut().as_mut() {
|
||||||
if url.cannot_be_a_base() { return; }
|
// Step 3.
|
||||||
|
Some(ref url) if url.cannot_be_a_base() => return,
|
||||||
|
None => return,
|
||||||
// Step 5.
|
// Step 5.
|
||||||
UrlHelper::SetPathname(url, value);
|
Some(url) => {
|
||||||
// Step 6.
|
UrlHelper::SetPathname(url, value);
|
||||||
self.update_href(url);
|
DOMString::from(url.as_str())
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// Step 6.
|
||||||
|
self.update_href(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-port
|
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-port
|
||||||
|
@ -341,17 +360,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||||
self.reinitialize_url();
|
self.reinitialize_url();
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
if let Some(url) = self.url.borrow_mut().as_mut() {
|
let url = match self.url.borrow_mut().as_mut() {
|
||||||
if url.host().is_none() ||
|
Some(ref url) if url.host().is_none() ||
|
||||||
url.cannot_be_a_base() ||
|
url.cannot_be_a_base() ||
|
||||||
url.scheme() == "file" {
|
url.scheme() == "file" => return,
|
||||||
return;
|
None => return,
|
||||||
}
|
|
||||||
// Step 4.
|
// Step 4.
|
||||||
UrlHelper::SetPort(url, value);
|
Some(url) => {
|
||||||
// Step 5.
|
UrlHelper::SetPort(url, value);
|
||||||
self.update_href(url);
|
DOMString::from(url.as_str())
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// Step 5.
|
||||||
|
self.update_href(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-protocol
|
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-protocol
|
||||||
|
@ -372,13 +393,17 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
self.reinitialize_url();
|
self.reinitialize_url();
|
||||||
|
|
||||||
// Step 2.
|
let url = match self.url.borrow_mut().as_mut() {
|
||||||
if let Some(url) = self.url.borrow_mut().as_mut() {
|
// Step 2.
|
||||||
|
None => return,
|
||||||
// Step 3.
|
// Step 3.
|
||||||
UrlHelper::SetProtocol(url, value);
|
Some(url) => {
|
||||||
// Step 4.
|
UrlHelper::SetProtocol(url, value);
|
||||||
self.update_href(url);
|
DOMString::from(url.as_str())
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// Step 4.
|
||||||
|
self.update_href(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-search
|
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-search
|
||||||
|
@ -399,15 +424,20 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
self.reinitialize_url();
|
self.reinitialize_url();
|
||||||
|
|
||||||
// Step 3.
|
// Step 2.
|
||||||
if let Some(url) = self.url.borrow_mut().as_mut() {
|
let url = match self.url.borrow_mut().as_mut() {
|
||||||
|
// Step 3.
|
||||||
|
None => return,
|
||||||
// Steps 4-5.
|
// Steps 4-5.
|
||||||
// TODO add this element's node document character encoding as
|
// TODO add this element's node document character encoding as
|
||||||
// encoding override (as described in the spec)
|
// encoding override (as described in the spec)
|
||||||
UrlHelper::SetSearch(url, value);
|
Some(url) => {
|
||||||
// Step 6.
|
UrlHelper::SetSearch(url, value);
|
||||||
self.update_href(url);
|
DOMString::from(url.as_str())
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// Step 6.
|
||||||
|
self.update_href(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-username
|
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-username
|
||||||
|
@ -428,17 +458,19 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
self.reinitialize_url();
|
self.reinitialize_url();
|
||||||
|
|
||||||
// Step 3.
|
// Step 2.
|
||||||
if let Some(url) = self.url.borrow_mut().as_mut() {
|
let url = match self.url.borrow_mut().as_mut() {
|
||||||
if url.host().is_none() || url.cannot_be_a_base() {
|
// Step 3.
|
||||||
return;
|
Some(ref url) if url.host().is_none() || url.cannot_be_a_base() => return,
|
||||||
}
|
None => return,
|
||||||
|
|
||||||
// Step 4.
|
// Step 4.
|
||||||
UrlHelper::SetUsername(url, value);
|
Some(url) => {
|
||||||
// Step 5.
|
UrlHelper::SetUsername(url, value);
|
||||||
self.update_href(url);
|
DOMString::from(url.as_str())
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// Step 5.
|
||||||
|
self.update_href(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-href
|
// https://html.spec.whatwg.org/multipage/#dom-hyperlink-href
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue