Skip to content

Commit

Permalink
Handle trailing build metadata in Python version string
Browse files Browse the repository at this point in the history
Don't fail Python versions when the version string contains trailing
build metadata after the `+` (as per: https://semver.org/#spec-item-10).
  • Loading branch information
andrewjcg committed Nov 6, 2023
1 parent 75adc45 commit e9b6641
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Version {
pub fn scan_bytes(data: &[u8]) -> Result<Version, Error> {
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();
}
Expand Down Expand Up @@ -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()
}
);
}
}

0 comments on commit e9b6641

Please sign in to comment.