From: Alexander Kriegisch Date: Sun, 10 Dec 2023 06:28:37 +0000 (+0700) Subject: Make OutputSpec::getTrimmedLines work for empty lines on Windows X-Git-Tag: V1_9_21~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=920e9f5f15dc8e4e2962357f351bf74c7d9b666e;p=aspectj.git 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 --- 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; } }