Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore trailing commas in versions #15

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading