fix parsing semi-colons after quoted text

Closes #64
This commit is contained in:
Sean McArthur 2017-10-11 12:57:31 -07:00
parent 2eea649b27
commit 94cf6c19e4
2 changed files with 28 additions and 2 deletions

View File

@ -773,6 +773,10 @@ mod tests {
assert_eq!(Mime::from_str("text/plain; charset=utf-8").unwrap(), TEXT_PLAIN_UTF_8);
assert_eq!(Mime::from_str("text/plain;charset=\"utf-8\"").unwrap(), TEXT_PLAIN_UTF_8);
// quotes + semi colon
Mime::from_str("text/plain;charset=\"utf-8\"; foo=bar").unwrap();
Mime::from_str("text/plain;charset=\"utf-8\" ; foo=bar").unwrap();
let upper = Mime::from_str("TEXT/PLAIN").unwrap();
assert_eq!(upper, TEXT_PLAIN);
assert_eq!(upper.type_(), TEXT);

View File

@ -144,7 +144,6 @@ fn params_from_str(s: &str, iter: &mut Enumerate<Bytes>, mut start: usize) -> Re
match iter.next() {
Some((i, b'"')) if i > start => {
value = Indexed(start, i);
start = i + 1;
break 'value;
},
Some((_, c)) if is_restricted_quoted_char(c) => (),
@ -154,7 +153,6 @@ fn params_from_str(s: &str, iter: &mut Enumerate<Bytes>, mut start: usize) -> Re
byte: byte,
}),
}
} else {
match iter.next() {
Some((i, b'"')) if i == start => {
@ -181,6 +179,30 @@ fn params_from_str(s: &str, iter: &mut Enumerate<Bytes>, mut start: usize) -> Re
}
}
if is_quoted {
'ws: loop {
match iter.next() {
Some((i, b';')) => {
// next param
start = i + 1;
break 'ws;
},
Some((_, b' ')) => {
// skip whitespace
},
None => {
// eof
start = s.len();
break 'ws;
},
Some((pos, byte)) => return Err(ParseError::InvalidToken {
pos: pos,
byte: byte,
}),
}
}
}
match params {
ParamSource::Utf8(i) => {
let i = i + 2;