Skip to content

Commit

Permalink
Add invalid version check for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kl committed Nov 22, 2024
1 parent c9129b3 commit a151fdd
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion mullvad-version/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,16 @@ fn to_android_version_code(version: &str) -> String {

fn to_windows_h_format(version: &str) -> String {
let Version {
year, incremental, ..
year,
incremental,
version_type,
..
} = Version::parse(version);

if !is_valid_windows_version(&version_type) {
panic!("Invalid Windows version type: {version_type:?}");
}

format!(
"#define MAJOR_VERSION 20{year}
#define MINOR_VERSION {incremental}
Expand All @@ -82,6 +89,13 @@ fn to_windows_h_format(version: &str) -> String {
)
}

fn is_valid_windows_version(version_type: &VersionType) -> bool {
matches!(
version_type,
VersionType::Beta(_) | VersionType::Dev(_) | VersionType::Stable
)
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -106,4 +120,10 @@ mod tests {
assert_eq!("21349000", to_android_version_code("2021.34-dev"));
assert_eq!("21349000", to_android_version_code("2021.34-dev-be846a5f0"));
}

#[test]
#[should_panic]
fn test_invalid_windows_version_code() {
to_windows_h_format("2021.34-alpha1");
}
}

0 comments on commit a151fdd

Please sign in to comment.