From bdcf1091932d3a60797cb2a09a8c72a053d87789 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Mon, 5 Feb 2024 20:38:58 +0100 Subject: [PATCH] Truncated errors now --- rc-zip-sync/tests/integration_tests.rs | 2 ++ rc-zip/src/parse/local_headers.rs | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/rc-zip-sync/tests/integration_tests.rs b/rc-zip-sync/tests/integration_tests.rs index a459318..e371611 100644 --- a/rc-zip-sync/tests/integration_tests.rs +++ b/rc-zip-sync/tests/integration_tests.rs @@ -15,10 +15,12 @@ fn check_case(test: &Case, archive: Result, Err }; for file in &test.files { + tracing::info!("checking file {}", file.name); let entry = archive .by_name(file.name) .unwrap_or_else(|| panic!("entry {} should exist", file.name)); + tracing::info!("got entry for {}", file.name); corpus::check_file_against(file, &entry, &entry.bytes().unwrap()[..]) } } diff --git a/rc-zip/src/parse/local_headers.rs b/rc-zip/src/parse/local_headers.rs index 9fb7f1e..debf98a 100644 --- a/rc-zip/src/parse/local_headers.rs +++ b/rc-zip/src/parse/local_headers.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use crate::{ - encoding::Encoding, + encoding::{detect_utf8, Encoding}, error::{Error, FormatError, UnsupportedError}, parse::{Method, MsdosTimestamp, Version}, }; @@ -122,18 +122,19 @@ impl<'a> LocalFileHeader<'a> { self.flags & 0b1000 != 0 } - /// + /// Converts the local file header into an entry. pub fn as_entry(&self) -> Result { // see APPNOTE 4.4.4: Bit 11 is the language encoding flag (EFS) let has_utf8_flag = self.flags & 0x800 == 0; - let encoding = if has_utf8_flag { + let encoding = if has_utf8_flag && detect_utf8(&self.name[..]).0 { Encoding::Utf8 } else { Encoding::Cp437 }; + let name = encoding.decode(&self.name[..])?; let mut entry = Entry { - name: encoding.decode(&self.name[..])?, + name, method: self.method, comment: Default::default(), modified: self.modified.to_datetime().unwrap_or_else(zero_datetime),