Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/org/apache/maven/shared/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,9 @@ public static String chop(@NonNull String str) {
*/
@NonNull
public static String chopNewline(@NonNull String str) {
if (str.isEmpty()) {
return "";
}
int lastIdx = str.length() - 1;
char last = str.charAt(lastIdx);
if (last == '\n') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ public void testChopNewline() {
assertEquals("dings\n\r", StringUtils.chopNewline("dings\n\r"));
}

@Test
public void testChopNewlineEmptyString() {
assertEquals("", StringUtils.chopNewline(""));
}

@Test
public void testClean() {
assertEquals("", StringUtils.clean(null));
Expand Down
Loading