From 3e61d20b40ae27159d16cb4c8eeb5f84803f87fe Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 2 Mar 2024 21:49:50 +1300 Subject: [PATCH] LibDiff: Handle parsing patches containing timestamps separated by \t This is still a very naive implementation and there are plenty of other cases that we should handle (like a quoted path) - but just looking for a tab handles the common case. --- Tests/Utilities/TestPatch.cpp | 15 +++++++++++++++ Userland/Libraries/LibDiff/Hunks.cpp | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Tests/Utilities/TestPatch.cpp b/Tests/Utilities/TestPatch.cpp index 32c0901fa8..123533feeb 100644 --- a/Tests/Utilities/TestPatch.cpp +++ b/Tests/Utilities/TestPatch.cpp @@ -261,3 +261,18 @@ TEST_CASE(patch_remove_file_trailing_garbage) EXPECT_FILE_EQ(ByteString::formatted("{}/a", s_test_dir), "2\n"sv); } + +TEST_CASE(patch_with_timestamp_separated_by_tab) +{ + PatchSetup setup; + + auto patch = R"( +--- /dev/null 2024-03-02 20:19:31.462146900 +1300 ++++ 1 2024-03-02 20:56:57.922136203 +1300 +@@ -0,0 +1 @@ ++a +)"sv; + + run_patch(ExpectSuccess::Yes, {}, patch, "patching file 1\n"sv); + EXPECT_FILE_EQ(ByteString::formatted("{}/1", s_test_dir), "a\n"sv); +} diff --git a/Userland/Libraries/LibDiff/Hunks.cpp b/Userland/Libraries/LibDiff/Hunks.cpp index c6b9398f19..cbc495c9e5 100644 --- a/Userland/Libraries/LibDiff/Hunks.cpp +++ b/Userland/Libraries/LibDiff/Hunks.cpp @@ -61,7 +61,10 @@ bool Parser::consume_line_number(size_t& number) ErrorOr Parser::parse_file_line(Optional const& strip_count) { // FIXME: handle parsing timestamps as well. - auto path = consume_line(); + auto line = consume_line(); + + GenericLexer line_parser(line); + auto path = line_parser.consume_until('\t'); // No strip count given. Default to basename of file. if (!strip_count.has_value())