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

Allow empty values in WHEEL files #2170

Merged
merged 1 commit into from
Mar 4, 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
29 changes: 21 additions & 8 deletions crates/install-wheel-rs/src/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,15 @@ fn parse_key_value_file(
if line.is_empty() {
continue;
}
let (key, value) = line.split_once(": ").ok_or_else(|| {
let (key, value) = line.split_once(':').ok_or_else(|| {
Error::InvalidWheel(format!(
"Line {} of the {debug_filename} file is invalid",
line_no + 1
))
})?;
data.entry(key.to_string())
data.entry(key.trim().to_string())
.or_default()
.push(value.to_string());
.push(value.trim().to_string());
}
Ok(data)
}
Expand Down Expand Up @@ -724,6 +724,7 @@ mod test {
use std::io::Cursor;
use std::path::Path;

use crate::Error;
use indoc::{formatdoc, indoc};

use crate::wheel::format_shebang;
Expand Down Expand Up @@ -890,22 +891,34 @@ mod test {
}

#[test]
fn test_invalid_wheel() {
fn test_empty_value() -> Result<(), Error> {
let wheel = indoc! {r"
Wheel-Version: 1.0
Generator: custom
Root-Is-Purelib: false
Tag:
Tag:
Tag: -manylinux_2_17_x86_64
Tag: -manylinux2014_x86_64
"
};
let reader = Cursor::new(wheel.to_string().into_bytes());
let err = parse_key_value_file(reader, "WHEEL").unwrap_err();
let wheel_file = parse_key_value_file(reader, "WHEEL")?;
assert_eq!(
err.to_string(),
"The wheel is invalid: Line 4 of the WHEEL file is invalid"
wheel_file.get("Wheel-Version"),
Some(&["1.0".to_string()].to_vec())
);
assert_eq!(
wheel_file.get("Tag"),
Some(
&[
String::new(),
"-manylinux_2_17_x86_64".to_string(),
"-manylinux2014_x86_64".to_string()
]
.to_vec()
)
);
Ok(())
}

#[test]
Expand Down