konsti 2023-12-28 15:40:42 +01:00 committed by GitHub
parent 0ebff943e4
commit 7bf2790a25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,9 +19,8 @@ static INVALID_TRAILING_DOT_STAR: Lazy<Regex> =
static MISSING_DOT: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d\.\d)+\*").unwrap()); static MISSING_DOT: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d\.\d)+\*").unwrap());
/// Ex) `>=3.6,` /// Ex) `>=3.6,`
static TRAILING_COMMA: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d\.(\d|\*))+,$").unwrap()); static TRAILING_COMMA: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d\.(\d|\*))+,$").unwrap());
/// Ex) `>= '2.7'` /// Ex) `>= '2.7'`, `>=3.6'`
static INVALID_QUOTES: Lazy<Regex> = static STRAY_QUOTES: Lazy<Regex> = Lazy::new(|| Regex::new(r#"['"]"#).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 /// Regex to match the invalid specifier, replacement to fix it and message about was wrong and
/// fixed /// fixed
@ -45,7 +44,7 @@ static FIXUPS: &[(&Lazy<Regex>, &str, &str)] = &[
// Given `>=3.6,`, rewrite to `>=3.6` // Given `>=3.6,`, rewrite to `>=3.6`
(&TRAILING_COMMA, r"${1}", "removing trailing comma"), (&TRAILING_COMMA, r"${1}", "removing trailing comma"),
// Given `>= '2.7'`, rewrite to `>= 2.7` // Given `>= '2.7'`, rewrite to `>= 2.7`
(&INVALID_QUOTES, r"${1}${2}", "removing invalid quotes"), (&STRAY_QUOTES, r"", "removing stray quotes"),
]; ];
fn parse_with_fixups<Err, T: FromStr<Err = Err>>(input: &str, type_name: &str) -> Result<T, Err> { fn parse_with_fixups<Err, T: FromStr<Err = Err>>(input: &str, type_name: &str) -> Result<T, Err> {
@ -283,4 +282,21 @@ mod tests {
VersionSpecifiers::from_str(">=2.7,!=3.0.*,!=3.1.*,<3.4").unwrap(); VersionSpecifiers::from_str(">=2.7,!=3.0.*,!=3.1.*,<3.4").unwrap();
assert_eq!(actual, expected); assert_eq!(actual, expected);
} }
/// <https://pypi.org/simple/algoliasearch/?format=application/vnd.pypi.simple.v1+json>
/// <https://pypi.org/simple/okta/?format=application/vnd.pypi.simple.v1+json>
#[test]
fn stray_quote() {
let actual: VersionSpecifiers =
LenientVersionSpecifiers::from_str(">=2.7, !=3.0.*, !=3.1.*', !=3.2.*, !=3.3.*'")
.unwrap()
.into();
let expected: VersionSpecifiers =
VersionSpecifiers::from_str(">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*").unwrap();
assert_eq!(actual, expected);
let actual: VersionSpecifiers =
LenientVersionSpecifiers::from_str(">=3.6'").unwrap().into();
let expected: VersionSpecifiers = VersionSpecifiers::from_str(">=3.6").unwrap();
assert_eq!(actual, expected);
}
} }