mirror of https://github.com/rwf2/Rocket.git
Relax FormItems iterator slicing rules a little.
This commit is contained in:
parent
f5ec470a7d
commit
7830a09f1e
|
@ -212,11 +212,9 @@ impl<'f> Iterator for FormItems<'f> {
|
|||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let s = &self.string[self.next_index..];
|
||||
let (key, rest) = match memchr2(b'=', b'&', s.as_bytes()) {
|
||||
Some(i) if s.as_bytes()[i] == b'=' => (&s[..i], &s[(i + 1)..]),
|
||||
Some(_) => return None,
|
||||
None => return None,
|
||||
};
|
||||
match memchr2(b'=', b'&', s.as_bytes()) {
|
||||
Some(i) if s.as_bytes()[i] == b'=' => {
|
||||
let (key, rest) = (&s[..i], &s[(i + 1)..]);
|
||||
|
||||
if key.is_empty() {
|
||||
return None;
|
||||
|
@ -230,6 +228,28 @@ impl<'f> Iterator for FormItems<'f> {
|
|||
self.next_index += key.len() + 1 + consumed;
|
||||
Some((key.into(), value.into()))
|
||||
}
|
||||
Some(i) => {
|
||||
let (value, consumed) = (&s[..i], i + 1);
|
||||
|
||||
if value.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.next_index += consumed;
|
||||
Some(("".into(), value.into()))
|
||||
}
|
||||
None => {
|
||||
let (value, consumed) = (&s[..], s.as_bytes().len());
|
||||
|
||||
if value.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.next_index += consumed;
|
||||
Some(("".into(), value.into()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -282,9 +302,13 @@ mod test {
|
|||
check_form!("user=&", &[("user", "")]);
|
||||
check_form!("a=b&a=", &[("a", "b"), ("a", "")]);
|
||||
|
||||
check_form!(@bad "user=&password");
|
||||
check_form!("user=&password", &[("user", ""), ("", "password")]);
|
||||
check_form!("a=b&a", &[("a", "b"), ("", "a")]);
|
||||
|
||||
check_form!("a&b&c", &[("", "a"), ("", "b"), ("", "c")]);
|
||||
check_form!("abc", &[("", "abc")]);
|
||||
|
||||
check_form!(@bad "user=x&&");
|
||||
check_form!(@bad "a=b&a");
|
||||
check_form!(@bad "=");
|
||||
check_form!(@bad "&");
|
||||
check_form!(@bad "=&");
|
||||
|
|
Loading…
Reference in New Issue