mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Change Namespace::from_str to take &str, fix #1367
This commit is contained in:
parent
5b0768c4f6
commit
ae0cbda327
3 changed files with 9 additions and 9 deletions
|
@ -15,6 +15,7 @@
|
||||||
//! onto these objects and cause use-after-free.
|
//! onto these objects and cause use-after-free.
|
||||||
|
|
||||||
use extra::url::Url;
|
use extra::url::Url;
|
||||||
|
use script::dom::bindings::utils::null_str_as_empty_ref;
|
||||||
use script::dom::element::{Element, HTMLAreaElementTypeId, HTMLAnchorElementTypeId};
|
use script::dom::element::{Element, HTMLAreaElementTypeId, HTMLAnchorElementTypeId};
|
||||||
use script::dom::element::{HTMLLinkElementTypeId};
|
use script::dom::element::{HTMLLinkElementTypeId};
|
||||||
use script::dom::htmliframeelement::HTMLIFrameElement;
|
use script::dom::htmliframeelement::HTMLIFrameElement;
|
||||||
|
@ -405,7 +406,7 @@ impl<'le> TElement for LayoutElement<'le> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_attr(&self, ns_url: Option<~str>, name: &str) -> Option<&'static str> {
|
fn get_attr(&self, ns_url: Option<~str>, name: &str) -> Option<&'static str> {
|
||||||
let namespace = Namespace::from_str(ns_url);
|
let namespace = Namespace::from_str(null_str_as_empty_ref(&ns_url));
|
||||||
unsafe { self.element.get_attr_val_for_layout(namespace, name) }
|
unsafe { self.element.get_attr_val_for_layout(namespace, name) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
use dom::attr::Attr;
|
use dom::attr::Attr;
|
||||||
use dom::attrlist::AttrList;
|
use dom::attrlist::AttrList;
|
||||||
use dom::bindings::utils::{Reflectable, DOMString, ErrorResult, Fallible, Reflector};
|
use dom::bindings::utils::{Reflectable, DOMString, ErrorResult, Fallible, Reflector};
|
||||||
use dom::bindings::utils::NamespaceError;
|
use dom::bindings::utils::{null_str_as_empty_ref, NamespaceError};
|
||||||
use dom::bindings::utils::{InvalidCharacter, QName, Name, InvalidXMLName, xml_name_type};
|
use dom::bindings::utils::{InvalidCharacter, QName, Name, InvalidXMLName, xml_name_type};
|
||||||
use dom::htmlcollection::HTMLCollection;
|
use dom::htmlcollection::HTMLCollection;
|
||||||
use dom::clientrect::ClientRect;
|
use dom::clientrect::ClientRect;
|
||||||
|
@ -402,7 +402,7 @@ impl Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn GetAttributeNS(&self, namespace: Option<DOMString>, local_name: DOMString) -> Option<DOMString> {
|
pub fn GetAttributeNS(&self, namespace: Option<DOMString>, local_name: DOMString) -> Option<DOMString> {
|
||||||
let namespace = Namespace::from_str(namespace);
|
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace));
|
||||||
self.get_attribute(namespace, local_name)
|
self.get_attribute(namespace, local_name)
|
||||||
.map(|attr| attr.value.clone())
|
.map(|attr| attr.value.clone())
|
||||||
}
|
}
|
||||||
|
@ -430,7 +430,7 @@ impl Element {
|
||||||
QName => {}
|
QName => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let namespace = Namespace::from_str(namespace_url);
|
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url));
|
||||||
self.set_attribute(abstract_self, namespace, name, value)
|
self.set_attribute(abstract_self, namespace, name, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,7 +449,7 @@ impl Element {
|
||||||
abstract_self: AbstractNode,
|
abstract_self: AbstractNode,
|
||||||
namespace: Option<DOMString>,
|
namespace: Option<DOMString>,
|
||||||
localname: DOMString) -> ErrorResult {
|
localname: DOMString) -> ErrorResult {
|
||||||
let namespace = Namespace::from_str(namespace);
|
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace));
|
||||||
self.remove_attribute(abstract_self, namespace, localname)
|
self.remove_attribute(abstract_self, namespace, localname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::utils::{DOMString, null_str_as_empty_ref};
|
|
||||||
|
|
||||||
#[deriving(Eq, Clone)]
|
#[deriving(Eq, Clone)]
|
||||||
pub enum Namespace {
|
pub enum Namespace {
|
||||||
Null,
|
Null,
|
||||||
|
@ -17,8 +15,9 @@ pub enum Namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Namespace {
|
impl Namespace {
|
||||||
pub fn from_str(url: Option<DOMString>) -> Namespace {
|
/// Empty string for "no namespace"
|
||||||
match null_str_as_empty_ref(&url) {
|
pub fn from_str(url: &str) -> Namespace {
|
||||||
|
match url {
|
||||||
"http://www.w3.org/1999/xhtml" => HTML,
|
"http://www.w3.org/1999/xhtml" => HTML,
|
||||||
"http://www.w3.org/XML/1998/namespace" => XML,
|
"http://www.w3.org/XML/1998/namespace" => XML,
|
||||||
"http://www.w3.org/2000/xmlns/" => XMLNS,
|
"http://www.w3.org/2000/xmlns/" => XMLNS,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue