mirror of
https://gitee.com/openharmony/third_party_rust_mime
synced 2024-11-23 13:09:43 +00:00
parent
2eea649b27
commit
94cf6c19e4
@ -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);
|
||||
|
26
src/parse.rs
26
src/parse.rs
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user