diff --git a/crates/pypi-types/src/lenient_requirement.rs b/crates/pypi-types/src/lenient_requirement.rs index 19f1e883e..84982f511 100644 --- a/crates/pypi-types/src/lenient_requirement.rs +++ b/crates/pypi-types/src/lenient_requirement.rs @@ -18,6 +18,9 @@ static GREATER_THAN_STAR: Lazy = Lazy::new(|| Regex::new(r">=(\d+\.\d+)\. static MISSING_DOT: Lazy = Lazy::new(|| Regex::new(r"(\d\.\d)+\*").unwrap()); /// Ex) `>=3.6,` static TRAILING_COMMA: Lazy = Lazy::new(|| Regex::new(r"(\d\.\d)+,$").unwrap()); +/// Ex) `>= '2.7'` +static INVALID_QUOTES: Lazy = + Lazy::new(|| Regex::new(r"((?:~=|==|!=|<=|>=|<|>|===) )*'(\d(?:\.\d)*)'").unwrap()); /// Regex to match the invalid specifier, replacement to fix it and message about was wrong and /// fixed @@ -40,6 +43,8 @@ static FIXUPS: &[(&Lazy, &str, &str)] = &[ (&MISSING_DOT, r"${1}.*", "Inserting missing dot"), // Given `>=3.6,`, rewrite to `>=3.6` (&TRAILING_COMMA, r"${1}", "Removing trailing comma"), + // Given `>= '2.7'`, rewrite to `>= 2.7` + (&INVALID_QUOTES, r"${1}${2}", "Removing invalid quotes"), ]; /// Like [`Requirement`], but attempts to correct some common errors in user-provided requirements. @@ -237,4 +242,14 @@ mod tests { let expected: VersionSpecifiers = VersionSpecifiers::from_str(">=3.6").unwrap(); assert_eq!(actual, expected); } + + /// + #[test] + fn specifier_invalid_quotes() { + let actual: VersionSpecifiers = LenientVersionSpecifiers::from_str(">= '2.7'") + .unwrap() + .into(); + let expected: VersionSpecifiers = VersionSpecifiers::from_str(">= 2.7").unwrap(); + assert_eq!(actual, expected); + } }