Fixup for >= '2.7' (#485)

Fixup to allow parsing
https://pypi.org/simple/shellingham/?format=application/vnd.pypi.simple.v1+json
This commit is contained in:
konsti 2023-11-22 11:00:12 +01:00 committed by GitHub
parent 7c7daa8f83
commit ff1100a1ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,9 @@ static GREATER_THAN_STAR: Lazy<Regex> = Lazy::new(|| Regex::new(r">=(\d+\.\d+)\.
static MISSING_DOT: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d\.\d)+\*").unwrap());
/// Ex) `>=3.6,`
static TRAILING_COMMA: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d\.\d)+,$").unwrap());
/// Ex) `>= '2.7'`
static INVALID_QUOTES: Lazy<Regex> =
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<Regex>, &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);
}
/// <https://pypi.org/simple/shellingham/?format=application/vnd.pypi.simple.v1+json>
#[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);
}
}