From 1d0fc8a8d2a1c22c5cfb6a0ec4daf81551cb00af Mon Sep 17 00:00:00 2001 From: Dmitry Gusarov <1462777+gusarov@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:48:40 -0400 Subject: [PATCH] Fix zero length matches --- Grepl.Tests/Commands/BasicCommands.cs | 19 +++++++++++++++++++ Grepl/Executor.cs | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/Grepl.Tests/Commands/BasicCommands.cs b/Grepl.Tests/Commands/BasicCommands.cs index 775eb23..76aca70 100644 --- a/Grepl.Tests/Commands/BasicCommands.cs +++ b/Grepl.Tests/Commands/BasicCommands.cs @@ -627,5 +627,24 @@ public void Should_30_show_only_file_name_replace_save() } + [TestMethod] + public void Should_10_exclude_zero_length_match() + { + File.WriteAllText("test.txt", "abc\n"); + + var r = GreplEntry(".*", "-r"); + Assert.AreEqual(0, r.Code); + + var raw = r.Output; + var exp = @" +test.txt +abc +"; + + CompareDetails(exp, raw); + + Assert.AreEqual(exp, raw); + + } } } diff --git a/Grepl/Executor.cs b/Grepl/Executor.cs index d34f733..5e2d402 100644 --- a/Grepl/Executor.cs +++ b/Grepl/Executor.cs @@ -269,6 +269,10 @@ void Process(string file, bool printFileName, Dictionary= length (zero length match at the end of a string) + } // find the start of the line var lineStart = body.LastIndexOf('\n', match.Index); lineStart++;