Skip to content

Commit

Permalink
change firefox version logic to be more robust and return a value of …
Browse files Browse the repository at this point in the history
…0 if unparsable, updated related tests
  • Loading branch information
taddes committed Oct 18, 2024
1 parent 9e0f013 commit c2ff37c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions syncserver/src/server/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ pub fn get_device_info(user_agent: &str) -> DeviceInfo {
DeviceFamily::Other => Platform::Other,
};

let firefox_version =
u32::from_str(w_result.version.split('.').collect::<Vec<&str>>()[0]).unwrap_or_default();
let firefox_version = w_result
.version
.split('.')
.next()
.and_then(|v| v.parse::<u32>().ok())
.unwrap_or(0);

DeviceInfo {
platform,
Expand Down Expand Up @@ -279,6 +283,7 @@ mod tests {
assert_eq!(device_info.platform, Platform::FirefoxIOS);
assert_eq!(device_info.device_family, DeviceFamily::Mobile);
assert_eq!(device_info.os_family, OsFamily::IOS);
assert_eq!(device_info.firefox_version, 0);
}

#[test]
Expand All @@ -288,5 +293,6 @@ mod tests {
assert_eq!(device_info.platform, Platform::FirefoxIOS);
assert_eq!(device_info.device_family, DeviceFamily::Mobile);
assert_eq!(device_info.os_family, OsFamily::IOS);
assert_eq!(device_info.firefox_version, 0);
}
}

0 comments on commit c2ff37c

Please sign in to comment.