From 47290f784e3878e45c497c91d7be24ae951cb005 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 15 Dec 2023 13:11:22 -0500 Subject: [PATCH] Add fixup for invalid double quotes (#663) Closes https://github.com/astral-sh/puffin/issues/658. --- crates/pypi-types/src/lenient_requirement.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/pypi-types/src/lenient_requirement.rs b/crates/pypi-types/src/lenient_requirement.rs index 876bf107b..cf2e1641f 100644 --- a/crates/pypi-types/src/lenient_requirement.rs +++ b/crates/pypi-types/src/lenient_requirement.rs @@ -20,7 +20,7 @@ static MISSING_DOT: Lazy = Lazy::new(|| Regex::new(r"(\d\.\d)+\*").unwrap 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()); + 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 @@ -239,7 +239,7 @@ mod tests { /// #[test] - fn specifier_invalid_quotes() { + fn specifier_invalid_single_quotes() { let actual: VersionSpecifiers = LenientVersionSpecifiers::from_str(">= '2.7'") .unwrap() .into(); @@ -247,6 +247,16 @@ mod tests { assert_eq!(actual, expected); } + /// + #[test] + fn specifier_invalid_double_quotes() { + let actual: VersionSpecifiers = LenientVersionSpecifiers::from_str(">=\"3.6\"") + .unwrap() + .into(); + let expected: VersionSpecifiers = VersionSpecifiers::from_str(">=3.6").unwrap(); + assert_eq!(actual, expected); + } + /// #[test] fn specifier_multi_fix() {