diff --git a/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java b/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java index c1c38d34..5d10da38 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java +++ b/core/src/main/java/com/google/googlejavaformat/java/StringWrapper.java @@ -225,7 +225,9 @@ private void indentTextBlocks( } if (i == lines.size() - 1) { String withoutDelimiter = - trimmed.substring(0, trimmed.length() - TEXT_BLOCK_DELIMITER.length()); + trimmed + .substring(0, trimmed.length() - TEXT_BLOCK_DELIMITER.length()) + .stripTrailing(); if (!withoutDelimiter.stripLeading().isEmpty()) { output.append(withoutDelimiter).append('\\').append(separator).append(prefix); } diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/I1205.input b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I1205.input new file mode 100644 index 00000000..8f8acaa1 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I1205.input @@ -0,0 +1,7 @@ +public interface Foo { + + private static String foo = + """ + foo\ + bar """; +} diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/I1205.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I1205.output new file mode 100644 index 00000000..c82862c0 --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/I1205.output @@ -0,0 +1,8 @@ +public interface Foo { + + private static String foo = + """ + foo\ + bar\ + """; +}