Skip to content

Commit 236aeed

Browse files
Notification message hardening
1 parent c23654a commit 236aeed

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

core/src/main/java/dev/vml/es/acm/core/util/StringUtil.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ private static String truncateCode(
3333
if (code == null || code.trim().isEmpty()) {
3434
return emptyMessage;
3535
}
36+
String humanSize = FileUtils.byteCountToDisplaySize(code.length());
3637
String text = StringUtils.trimToEmpty(code);
3738
if (maxLength < 0 || text.length() <= maxLength) {
38-
return "```\n" + text + "\n```";
39+
return String.format("%s\n```\n%s\n```", humanSize, text);
3940
}
4041
int skippedChars = text.length() - maxLength;
4142
String remaining;
@@ -50,15 +51,14 @@ private static String truncateCode(
5051
String skippedPart = text.substring(maxLength);
5152
skippedLines = skippedPart.isEmpty() ? 0 : skippedPart.split("\r?\n").length;
5253
}
53-
String humanSize = FileUtils.byteCountToDisplaySize(code.length());
5454
String lineWord = skippedLines == 1 ? "line" : "lines";
5555
String msg;
5656
if (skippedLines > 0) {
57-
msg = String.format("(%s, %d %s skipped)", humanSize, skippedLines, lineWord);
57+
msg = String.format("%s, %d %s skipped", humanSize, skippedLines, lineWord);
5858
} else {
59-
msg = String.format("(%s)", humanSize);
59+
msg = humanSize;
6060
}
61-
return msg + "\n```\n" + remaining + "\n```";
61+
return String.format("%s\n```\n%s\n```", msg, remaining);
6262
}
6363

6464
public static String truncateCodeStart(String code, int maxLength) {

0 commit comments

Comments
 (0)