mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Make WHEEL parsing error line numbers one indexed. (#2151)
Fixes an off-by-one from #2149. `enumerate` is zero-based, human line numbers are one based.
This commit is contained in:
parent
836b90c760
commit
bc0345a1fd
1 changed files with 23 additions and 2 deletions
|
@ -652,7 +652,7 @@ pub(crate) fn read_record_file(record: &mut impl Read) -> Result<Vec<RecordEntry
|
|||
|
||||
/// Parse a file with `Key: value` entries such as WHEEL and METADATA
|
||||
fn parse_key_value_file(
|
||||
file: &mut impl Read,
|
||||
file: impl Read,
|
||||
debug_filename: &str,
|
||||
) -> Result<FxHashMap<String, Vec<String>>, Error> {
|
||||
let mut data: FxHashMap<String, Vec<String>> = FxHashMap::default();
|
||||
|
@ -665,7 +665,8 @@ fn parse_key_value_file(
|
|||
}
|
||||
let (key, value) = line.split_once(": ").ok_or_else(|| {
|
||||
Error::InvalidWheel(format!(
|
||||
"Line {line_no} of the {debug_filename} file is invalid"
|
||||
"Line {} of the {debug_filename} file is invalid",
|
||||
line_no + 1
|
||||
))
|
||||
})?;
|
||||
data.entry(key.to_string())
|
||||
|
@ -720,6 +721,7 @@ pub(crate) fn parse_metadata(
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::io::Cursor;
|
||||
use std::path::Path;
|
||||
|
||||
use indoc::{formatdoc, indoc};
|
||||
|
@ -887,6 +889,25 @@ mod test {
|
|||
assert_eq!(format_shebang(executable, os_name), "#!/bin/sh\n'''exec' '/usr/bin/path/to/a/very/long/executable/executable/executable/executable/executable/executable/executable/executable/name/python3' \"$0\" \"$@\"\n' '''");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_wheel() {
|
||||
let wheel = indoc! {r"
|
||||
Wheel-Version: 1.0
|
||||
Generator: custom
|
||||
Root-Is-Purelib: false
|
||||
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();
|
||||
assert_eq!(
|
||||
err.to_string(),
|
||||
"The wheel is invalid: Line 4 of the WHEEL file is invalid"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(windows, target_arch = "x86_64"))]
|
||||
fn test_launchers_are_small() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue