From 45d977aa39641f51d8eb3ddb3fa751556eb1b9af Mon Sep 17 00:00:00 2001 From: Thomas O'Donnell Date: Wed, 20 Nov 2019 15:16:07 +0100 Subject: [PATCH] fix: Remove duplicated "v" in package versions (#648) --- src/modules/package.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/package.rs b/src/modules/package.rs index 2a2580f1e..9a5394d54 100644 --- a/src/modules/package.rs +++ b/src/modules/package.rs @@ -72,7 +72,12 @@ fn get_package_version() -> Option { } fn format_version(version: &str) -> String { - format!("v{}", version.replace('"', "").trim()) + let cleaned = version.replace('"', "").trim().to_string(); + if cleaned.starts_with('v') { + cleaned + } else { + format!("v{}", cleaned) + } } #[cfg(test)] @@ -82,6 +87,16 @@ mod tests { #[test] fn test_format_version() { assert_eq!(format_version("0.1.0"), "v0.1.0"); + assert_eq!(format_version(" 0.1.0 "), "v0.1.0"); + assert_eq!(format_version("0.1.0 "), "v0.1.0"); + assert_eq!(format_version(" 0.1.0"), "v0.1.0"); + assert_eq!(format_version("\"0.1.0\""), "v0.1.0"); + + assert_eq!(format_version("v0.1.0"), "v0.1.0"); + assert_eq!(format_version(" v0.1.0 "), "v0.1.0"); + assert_eq!(format_version(" v0.1.0"), "v0.1.0"); + assert_eq!(format_version("v0.1.0 "), "v0.1.0"); + assert_eq!(format_version("\"v0.1.0\""), "v0.1.0"); } #[test]