From 325d63618bae18c0b461186ebfd94c02eab66158 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 11 Jun 2026 00:16:12 -0500 Subject: [PATCH] Avoid panics for Unicode Python version requests ## Summary Prior to this change, a Unicode numeric character in a Python version request could cause variant parsing to panic. The parser treated the byte offset returned for the character as though the character were one byte long, then sliced through the middle of it. This restricts variant detection to ASCII digits, matching Python version syntax. Malformed Unicode numeric requests now return the existing invalid version error, with focused regression coverage. --- crates/uv-python/src/discovery.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/uv-python/src/discovery.rs b/crates/uv-python/src/discovery.rs index 3070135377301..378749f4ee253 100644 --- a/crates/uv-python/src/discovery.rs +++ b/crates/uv-python/src/discovery.rs @@ -3347,7 +3347,7 @@ impl FromStr for VersionRequest { return Err(Error::InvalidVersionRequest(s.to_string())); } - let Some(mut start) = s.rfind(|c: char| c.is_numeric()) else { + let Some(mut start) = s.rfind(|c: char| c.is_ascii_digit()) else { return Ok((s, PythonVariant::Default)); }; @@ -4330,6 +4330,10 @@ mod tests { VersionRequest::from_str("3.13tt"), Err(Error::InvalidVersionRequest(_)) )); + assert!(matches!( + VersionRequest::from_str("3.12²t"), + Err(Error::InvalidVersionRequest(_)) + )); // `==` specifiers are parsed as concrete version requests via `from_specifiers` assert_eq!(