Skip to content

Commit

Permalink
ignore trailing commas in versions
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-phylum committed May 20, 2024
1 parent 672437d commit ab38f3a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ fn parse_specifier(
/// Such as `>=1.19,<2.0`, either delimited by the end of the specifier or a `;` for the marker part
///
/// ```text
/// version_one (wsp* ',' version_one)*
/// version_one (wsp* ',' version_one)* (wsp* ',' wsp*)?
/// ```
fn parse_version_specifier(cursor: &mut Cursor) -> Result<Option<VersionOrUrl>, Pep508Error> {
let mut start = cursor.pos();
Expand All @@ -860,9 +860,11 @@ fn parse_version_specifier(cursor: &mut Cursor) -> Result<Option<VersionOrUrl>,
start = end + 1;
}
Some((_, ';')) | None => {
let end = cursor.pos();
let specifier = parse_specifier(cursor, &buffer, start, end)?;
specifiers.push(specifier);
if buffer.chars().any(|c| !c.is_whitespace()) {
let end = cursor.pos();
let specifier = parse_specifier(cursor, &buffer, start, end)?;
specifiers.push(specifier);
}
break Some(VersionOrUrl::VersionSpecifier(
specifiers.into_iter().collect(),
));
Expand Down Expand Up @@ -1171,6 +1173,13 @@ mod tests {
assert_eq!(numpy.name.as_ref(), "numpy");
}

#[test]
fn versions_trailing_comma() {
let with_trailing_comma = Requirement::from_str("numpy >=1.19, ").unwrap();
let without_trailing_comma = Requirement::from_str("numpy >=1.19").unwrap();
assert_eq!(with_trailing_comma, without_trailing_comma);
}

#[test]
fn error_extras_eof1() {
assert_err(
Expand Down

0 comments on commit ab38f3a

Please sign in to comment.