From 6afa61f81d9c12b2a3c5b00e2a94516fd7e34157 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 10 Jun 2026 17:21:52 -0700 Subject: [PATCH] Ignore reversed string compatible-release markers --- crates/uv-pep508/src/lib.rs | 7 +++++++ crates/uv-pep508/src/marker/parse.rs | 23 +++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/uv-pep508/src/lib.rs b/crates/uv-pep508/src/lib.rs index 911a33add60..a62d7860623 100644 --- a/crates/uv-pep508/src/lib.rs +++ b/crates/uv-pep508/src/lib.rs @@ -1457,6 +1457,13 @@ mod tests { Requirement::::from_str(r#"numpy; sys_platform == "win32" or (os_name == "linux" and implementation_name == 'cpython')"#).unwrap(); } + #[test] + fn reversed_compatible_release_string_marker() { + let requirement = Requirement::::from_str(r#"foo; "3" ~= sys_platform"#).unwrap(); + + assert_eq!(requirement.to_string(), "foo"); + } + #[test] fn error_marker_incomplete1() { assert_snapshot!( diff --git a/crates/uv-pep508/src/marker/parse.rs b/crates/uv-pep508/src/marker/parse.rs index 5ee101b15d3..aeeaa05f2e3 100644 --- a/crates/uv-pep508/src/marker/parse.rs +++ b/crates/uv-pep508/src/marker/parse.rs @@ -282,12 +282,23 @@ pub(crate) fn parse_marker_key_op_value( parse_inverted_version_expr(&l_string, operator, key, reporter) } // '...' == - MarkerValue::MarkerEnvString(key) => Some(MarkerExpression::String { - key, - // Invert the operator to normalize the expression order. - operator: operator.invert(), - value: l_string, - }), + MarkerValue::MarkerEnvString(key) => { + if operator == MarkerOperator::TildeEqual { + reporter.report( + MarkerWarningKind::LexicographicComparison, + "Can't compare strings with `~=`, will be ignored".to_string(), + ); + + return Ok(None); + } + + Some(MarkerExpression::String { + key, + // Invert the operator to normalize the expression order. + operator: operator.invert(), + value: l_string, + }) + } // `"test" in extras` or `"dev" in dependency_groups` MarkerValue::MarkerEnvList(key) => { let operator =