Skip to content

Commit

Permalink
Fix truncateTail.
Browse files Browse the repository at this point in the history
If the value and tail have been the same, the tail wasn't removed.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
  • Loading branch information
boaks committed May 16, 2024
1 parent d30df81 commit 9f7d5df
Showing 1 changed file with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -477,17 +477,9 @@ public static boolean truncateTail(StringBuilder builder, String tail) {
int tailLength = tail.length();
if (tailLength > 0) {
int end = builder.length() - tailLength;
if (end > 0) {
if (end >= 0 && builder.indexOf(tail, end) == end) {
builder.setLength(end);
truncated = true;
for (int index = 0; index < tailLength; ++index) {
if (builder.charAt(index + end) != tail.charAt(index)) {
truncated = false;
break;
}
}
if (truncated) {
builder.setLength(end);
}
}
}
return truncated;
Expand Down

0 comments on commit 9f7d5df

Please sign in to comment.