Skip to content

Commit 2c155e5

Browse files
committed
fix(parse_manpage_at_path): path extension check
1 parent 4ee04f5 commit 2c155e5

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/main.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,19 +1254,18 @@ fn parse_manpage_at_path(
12541254
// diagnostic_indent += 1
12551255

12561256
let mut manpage = String::new();
1257-
if manpage_path.ends_with(".gz") {
1257+
let extension = manpage_path.extension().unwrap_or_default();
1258+
let extension = extension.to_string_lossy();
1259+
if extension.as_ref() == "gz" {
12581260
let mut gz = GzDecoder::new(File::open(manpage_path)?);
12591261
gz.read_to_string(&mut manpage)?;
1260-
} else if manpage_path.ends_with(".bz2") {
1262+
} else if extension.as_ref() == "bz2" {
12611263
let mut bz = BzDecoder::new(File::open(manpage_path)?);
12621264
bz.read_to_string(&mut manpage)?;
1263-
} else if manpage_path.ends_with(".xz") || manpage_path.ends_with(".lzma") {
1265+
} else if extension.as_ref() == "xz" || extension.as_ref() == "lzma" {
12641266
let mut xz = XzDecoder::new(File::open(manpage_path)?);
12651267
xz.read_to_string(&mut manpage)?;
1266-
} else if [".1", ".2", ".3", ".4", ".5", ".6", ".7", ".8", ".9"]
1267-
.iter()
1268-
.any(|suffix| manpage_path.ends_with(suffix))
1269-
{
1268+
} else if (1..=9).any(|suffix| suffix.to_string() == extension.as_ref()) {
12701269
File::open(manpage_path)?.read_to_string(&mut manpage)?;
12711270
}
12721271

0 commit comments

Comments
 (0)