From e9b66412aefc05314036189a777fbfa4d5833060 Mon Sep 17 00:00:00 2001 From: Andrew Gallagher Date: Tue, 31 Oct 2023 08:22:46 -0700 Subject: [PATCH] Handle trailing build metadata in Python version string Don't fail Python versions when the version string contains trailing build metadata after the `+` (as per: https://semver.org/#spec-item-10). --- src/version.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/version.rs b/src/version.rs index f99e518b..27d8538b 100644 --- a/src/version.rs +++ b/src/version.rs @@ -15,7 +15,7 @@ impl Version { pub fn scan_bytes(data: &[u8]) -> Result { lazy_static! { static ref RE: Regex = Regex::new( - r"((2|3)\.(3|4|5|6|7|8|9|10|11)\.(\d{1,2}))((a|b|c|rc)\d{1,2})?\+? (.{1,64})" + r"((2|3)\.(3|4|5|6|7|8|9|10|11)\.(\d{1,2}))((a|b|c|rc)\d{1,2})?(\+(?:[0-9a-z-]+(?:[.][0-9a-z-]+)*)?)? (.{1,64})" ) .unwrap(); } @@ -140,5 +140,27 @@ mod tests { release_flags: "".to_owned() } ); + + let version = Version::scan_bytes(b"2.7.10+dcba (default)").unwrap(); + assert_eq!( + version, + Version { + major: 2, + minor: 7, + patch: 10, + release_flags: "".to_owned() + } + ); + + let version = Version::scan_bytes(b"2.7.10+5-4.abcd (default)").unwrap(); + assert_eq!( + version, + Version { + major: 2, + minor: 7, + patch: 10, + release_flags: "".to_owned() + } + ); } }