aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/str.rs
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2014-05-28 11:22:05 -0400
committerbors-servo <release+servo@mozilla.com>2014-05-28 11:22:05 -0400
commitd2263559ed269b3c8d44b8730b678df789099c83 (patch)
treefcab660f1db6647ad5c50b70c9d6099486897b15 /src/components/script/dom/bindings/str.rs
parentbe938c4bb6ee9e275ce73da4f604019748972fa0 (diff)
parent5f860bb61221d9fc1afce35e896db2805e4cdb5b (diff)
downloadservo-d2263559ed269b3c8d44b8730b678df789099c83.tar.gz
servo-d2263559ed269b3c8d44b8730b678df789099c83.zip
auto merge of #2493 : Manishearth/servo/xhr-post, r=jdm
Blocks #2282
Diffstat (limited to 'src/components/script/dom/bindings/str.rs')
-rw-r--r--src/components/script/dom/bindings/str.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/components/script/dom/bindings/str.rs b/src/components/script/dom/bindings/str.rs
index e0ac5e57a2e..a662470aeab 100644
--- a/src/components/script/dom/bindings/str.rs
+++ b/src/components/script/dom/bindings/str.rs
@@ -37,6 +37,7 @@ impl ByteString {
}
}).collect())
}
+
pub fn is_token(&self) -> bool {
let ByteString(ref vec) = *self;
vec.iter().all(|&x| {
@@ -51,6 +52,55 @@ impl ByteString {
}
})
}
+
+ pub fn is_field_value(&self) -> bool {
+ // Classifications of characters necessary for the [CRLF] (SP|HT) rule
+ #[deriving(Eq)]
+ enum PreviousCharacter {
+ Other,
+ CR,
+ LF,
+ SP_HT // SP or HT
+ }
+ let ByteString(ref vec) = *self;
+ let mut prev = Other; // The previous character
+ vec.iter().all(|&x| {
+ // http://tools.ietf.org/html/rfc2616#section-2.2
+ match x {
+ 13 => { // CR
+ if prev == Other || prev == SP_HT {
+ prev = CR;
+ true
+ } else {
+ false
+ }
+ },
+ 10 => { // LF
+ if prev == CR {
+ prev = LF;
+ true
+ } else {
+ false
+ }
+ },
+ 32 | 9 => { // SP | HT
+ if prev == LF || prev == SP_HT {
+ prev = SP_HT;
+ true
+ } else {
+ false
+ }
+ },
+ 0..31 | 127 => false, // CTLs
+ x if x > 127 => false, // non ASCII
+ _ if prev == Other || prev == SP_HT => {
+ prev = Other;
+ true
+ },
+ _ => false // Previous character was a CR/LF but not part of the [CRLF] (SP|HT) rule
+ }
+ })
+ }
}
impl Hash for ByteString {