aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/str.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/script/dom/bindings/str.rs')
-rw-r--r--src/components/script/dom/bindings/str.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/components/script/dom/bindings/str.rs b/src/components/script/dom/bindings/str.rs
index e7d84d21c07..ae6c721abea 100644
--- a/src/components/script/dom/bindings/str.rs
+++ b/src/components/script/dom/bindings/str.rs
@@ -2,7 +2,9 @@
* 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/. */
+use std::from_str::FromStr;
use std::hash::{Hash, sip};
+use std::path::BytesContainer;
use std::str;
#[deriving(Encodable,Clone,TotalEq,Eq)]
@@ -45,6 +47,9 @@ impl ByteString {
pub fn is_token(&self) -> bool {
let ByteString(ref vec) = *self;
+ if vec.len() == 0 {
+ return false; // A token must be at least a single character
+ }
vec.iter().all(|&x| {
// http://tools.ietf.org/html/rfc2616#section-2.2
match x {
@@ -53,6 +58,7 @@ impl ByteString {
44 | 59 | 58 | 92 | 34 |
47 | 91 | 93 | 63 | 61 |
123 | 125 | 32 => false, // separators
+ x if x > 127 => false, // non-CHARs
_ => true
}
})
@@ -113,4 +119,10 @@ impl Hash for ByteString {
let ByteString(ref vec) = *self;
vec.hash(state);
}
+}
+
+impl FromStr for ByteString {
+ fn from_str(s: &str) -> Option<ByteString> {
+ Some(ByteString::new(s.container_into_owned_bytes()))
+ }
} \ No newline at end of file