From 5f639493f030ebb78b1a232b781eb596793d70b3 Mon Sep 17 00:00:00 2001 From: Rummskartoffel Date: Mon, 17 Jan 2022 22:30:44 +0100 Subject: [PATCH] gunzip: Don't truncate output filename when input file suffix is omitted Before this commit, `$ gunzip abcd` would incorrectly uncompress `abcd.gz` to `a` instead of to `abcd`. --- Userland/Utilities/gunzip.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Userland/Utilities/gunzip.cpp b/Userland/Utilities/gunzip.cpp index 30902c22d7..cd8879577a 100644 --- a/Userland/Utilities/gunzip.cpp +++ b/Userland/Utilities/gunzip.cpp @@ -43,12 +43,14 @@ ErrorOr serenity_main(Main::Arguments args) for (auto filename : filenames) { String input_filename; - if (filename.ends_with(".gz")) + String output_filename; + if (filename.ends_with(".gz")) { input_filename = filename; - else + output_filename = filename.substring_view(0, filename.length() - 3); + } else { input_filename = String::formatted("{}.gz", filename); - - const auto output_filename = filename.substring_view(0, filename.length() - 3); + output_filename = filename; + } auto input_stream_result = TRY(Core::InputFileStream::open_buffered(input_filename));