Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,24 @@ public class HtmlEscaper {

public static void escape(String value, Writer writer) {
try {
char[] chars = value.toCharArray();
int length = chars.length;
int length = value.length();
int start = 0;
for (int i = 0; i < length; i++) {
char c = chars[i];
char c = value.charAt(i);
char[] escaped;
// We only possibly escape chars in the range 0-96
if (c <= 96 && (escaped = ESC[c]) != null) {
// Write from the last replacement to before this one
if (i > start) writer.write(chars, start, i - start);
if (i > start) writer.write(value, start, i - start);

@augmentcode augmentcode Bot Jul 31, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writer.write(String, int, int)’s default implementation allocates a new char[] per call; wrappers like LatchedWriter/IndentWriter that only override write(char[], …) may now allocate per clean span and potentially regress perf vs the previous toCharArray+slice approach. Consider validating benchmarks with those writers in the call chain to ensure this stays a win in typical rendering paths.

Other locations where this applies: compiler/src/main/java/com/github/mustachejava/util/HtmlEscaper.java:75

Severity: medium

Other Locations
  • compiler/src/main/java/com/github/mustachejava/util/HtmlEscaper.java:75

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

// Write the replacement
writer.write(escaped);
// Move the pointer to the position after replacement
start = i + 1;
}
}
writer.write(chars, start, length - start);
if (start < length) {
writer.write(value, start, length - start);
}
} catch (IOException e) {
throw new MustacheException("Failed to encode value: " + value, e);
}
Expand Down
Loading