Merge pull request #355 from figsoda/ext

fix handling of unknown extensions
This commit is contained in:
João Marcos 2023-01-31 19:57:05 -03:00 committed by GitHub
commit bc78e64739
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -24,6 +24,10 @@ Categories Used:
- Multi-threaded compression for gzip and snappy using gzp [\#348](https://github.com/ouch-org/ouch/pull/348) ([figsoda](https://github.com/figsoda))
### Bug fixes
- Fix handling of unknown extensions during decompression [\#355](https://github.com/ouch-org/ouch/pull/355) ([figsoda](https://github.com/figsoda))
## [0.4.1](https://github.com/ouch-org/ouch/compare/0.4.0...0.4.1)
### New Features

View File

@ -113,11 +113,12 @@ fn to_extension(ext: &[u8]) -> Option<Extension> {
))
}
fn split_extension<'a>(name: &mut &'a [u8]) -> Option<&'a [u8]> {
fn split_extension(name: &mut &[u8]) -> Option<Extension> {
let (new_name, ext) = name.rsplit_once_str(b".")?;
if matches!(new_name, b"" | b"." | b"..") {
return None;
}
let ext = to_extension(ext)?;
*name = new_name;
Some(ext)
}
@ -149,7 +150,7 @@ pub fn separate_known_extensions_from_name(path: &Path) -> (&Path, Vec<Extension
};
// While there is known extensions at the tail, grab them
while let Some(extension) = split_extension(&mut name).and_then(to_extension) {
while let Some(extension) = split_extension(&mut name) {
extensions.insert(0, extension);
}