Skip to content

Commit

Permalink
Fix User Agent parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
kurotych committed Mar 14, 2021
1 parent 071e2b6 commit 12f6dcf
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/sipmsg/src/headers/parsers/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ impl SipHeaderParser for UserAgent {
continue;
}

if tmp_input[0] == b'<' {
let (input, _) = take_sws_token::laquot(tmp_input)?;
let (input, _) = take_until(">")(input)?;
let (input, _) = take_sws_token::raquot(input)?;
tmp_input = input;
continue;
}

let (input, _) = take_while1(is_token_char)(tmp_input)?;
let (input, _) = take_sws(input)?;
tmp_input = input;
Expand All @@ -60,11 +68,18 @@ impl SipHeaderParser for UserAgent {
#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_server_value() {
let (input, val) = UserAgent::take_value("HomeServer v2\r\n".as_bytes()).unwrap();
assert_eq!(val.vstr, "HomeServer v2");
assert_eq!(input, b"\r\n");
}
#[test]
fn test_user_agent_val() {
let user_agent = "<Motorola VT1000 mac: 000CE5C74EF8 sw:VT20_02.03.00_A ln:0 cfg:1253778536520/1002173358>";
let ua_with_end_line = [user_agent, "\r\n"].join("");
let (input, val) = UserAgent::take_value(ua_with_end_line.as_bytes()).unwrap();
assert_eq!(val.vstr, user_agent);
assert_eq!(input, b"\r\n");
}
}

0 comments on commit 12f6dcf

Please sign in to comment.