Skip to content

Commit

Permalink
Fix sourc distribution filename escaping (#7421)
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin authored Sep 16, 2024
1 parent 6a9ec96 commit cad9343
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions crates/distribution-filename/src/source_dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ impl SourceDistFilename {

impl Display for SourceDistFilename {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}-{}.{}", self.name, self.version, self.extension)
write!(
f,
"{}-{}.{}",
self.name.as_dist_info_name(),
self.version,
self.extension
)
}
}

Expand Down Expand Up @@ -173,14 +179,17 @@ mod tests {
use crate::{SourceDistExtension, SourceDistFilename};

/// Only test already normalized names since the parsing is lossy
///
/// <https://packaging.python.org/en/latest/specifications/source-distribution-format/#source-distribution-file-name>
/// <https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode>
#[test]
fn roundtrip() {
for normalized in [
"foo-lib-1.2.3.zip",
"foo-lib-1.2.3a3.zip",
"foo-lib-1.2.3.tar.gz",
"foo-lib-1.2.3.tar.bz2",
"foo-lib-1.2.3.tar.zst",
"foo_lib-1.2.3.zip",
"foo_lib-1.2.3a3.zip",
"foo_lib-1.2.3.tar.gz",
"foo_lib-1.2.3.tar.bz2",
"foo_lib-1.2.3.tar.zst",
] {
let ext = SourceDistExtension::from_path(normalized).unwrap();
assert_eq!(
Expand Down

0 comments on commit cad9343

Please sign in to comment.