From 920e9f5f15dc8e4e2962357f351bf74c7d9b666e Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sun, 10 Dec 2023 13:28:37 +0700 Subject: [PATCH] Make OutputSpec::getTrimmedLines work for empty lines on Windows Improve the regex splitting lines to actually remove CR characters on Windows. Signed-off-by: Alexander Kriegisch --- testing/src/test/java/org/aspectj/testing/OutputSpec.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/testing/src/test/java/org/aspectj/testing/OutputSpec.java b/testing/src/test/java/org/aspectj/testing/OutputSpec.java index 14fc3bb62..def3990ec 100644 --- a/testing/src/test/java/org/aspectj/testing/OutputSpec.java +++ b/testing/src/test/java/org/aspectj/testing/OutputSpec.java @@ -127,8 +127,11 @@ public class OutputSpec { } private String[] getTrimmedLines(String text) { - // Remove leading/trailing empty lines and leading/trailing whitespace from each line - String[] trimmedLines = text.trim().split("\\s*\n\\s*"); + // Remove leading/trailing empty lines and leading/trailing horizontal whitespace from each line. + // Regex character class '\h' is horizonal whitespace. We assume that lines are always separated by something + // containing a '\n' LF character, e.g. LF (UNIX), CRLF (Windows). For legacy Mac platforms with their CR-only line + // separators, this would not work, and it is not supposed to either. + String[] trimmedLines = text.trim().split("\\h*\r?\n\\h*"); return trimmedLines.length == 1 && trimmedLines[0].equals("") ? new String[0] : trimmedLines; } } -- 2.39.5