From e48b9d74ac6f081117e3ce344a85d0f39d0e7325 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Thu, 14 Sep 2023 19:40:37 +0200 Subject: [PATCH] grep: Add comment describing why we take leading characters from paths --- Userland/Utilities/grep.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/grep.cpp b/Userland/Utilities/grep.cpp index d3f13421d6..5e83f47705 100644 --- a/Userland/Utilities/grep.cpp +++ b/Userland/Utilities/grep.cpp @@ -254,7 +254,8 @@ ErrorOr serenity_main(Main::Arguments args) while (it.has_next()) { auto path = it.next_full_path(); if (!FileSystem::is_directory(path)) { - auto key = user_has_specified_files ? path.view() : path.substring_view(base.length() + 1, path.length() - base.length() - 1); + // Remove leading './' when `grep -r` was run without any specified paths. + auto key = user_has_specified_files ? path.view() : path.substring_view(base.length() + 1); if (auto result = handle_file(key, true); result.is_error() && !suppress_errors) warnln("Failed with file {}: {}", key, result.release_error());