This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 99a485dcf0 Align JSON filter implementations.
99a485dcf0 is described below
commit 99a485dcf0a7a331b88963a2e31a0265279e6a05
Author: Mark Thomas <[email protected]>
AuthorDate: Wed May 27 17:16:13 2026 +0100
Align JSON filter implementations.
---
java/org/apache/juli/JsonFormatter.java | 8 ++------
java/org/apache/tomcat/util/json/JSONFilter.java | 16 ++++++++++------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/java/org/apache/juli/JsonFormatter.java
b/java/org/apache/juli/JsonFormatter.java
index 9f8707760a..d75c3c4c34 100644
--- a/java/org/apache/juli/JsonFormatter.java
+++ b/java/org/apache/juli/JsonFormatter.java
@@ -164,13 +164,10 @@ public class JsonFormatter extends OneLineFormatter {
escaped.append('\\').append(popular);
} else {
int v = c;
-
- escaped.append("\\u")
- .append(Character.forDigit((v >>> 12) & 0xF,
16))
+ escaped.append("\\u").append(Character.forDigit((v >>>
12) & 0xF, 16))
.append(Character.forDigit((v >>> 8) & 0xF,
16))
.append(Character.forDigit((v >>> 4) & 0xF,
16))
- .append(Character.forDigit(v & 0xF, 16))
- ;
+ .append(Character.forDigit(v & 0xF, 16));
}
}
}
@@ -203,6 +200,5 @@ public class JsonFormatter extends OneLineFormatter {
default -> 0;
};
}
-
}
}
diff --git a/java/org/apache/tomcat/util/json/JSONFilter.java
b/java/org/apache/tomcat/util/json/JSONFilter.java
index 8b0416962b..6bde8c89e6 100644
--- a/java/org/apache/tomcat/util/json/JSONFilter.java
+++ b/java/org/apache/tomcat/util/json/JSONFilter.java
@@ -85,7 +85,8 @@ public class JSONFilter {
*/
StringBuilder escaped = null;
int lastUnescapedStart = off;
- for (int i = off; i < off + length; i++) {
+ final int end = off + length;
+ for (int i = off; i < end; i++) {
char c = input.charAt(i);
if (c < 0x20 || c == 0x22 || c == 0x5c ||
Character.isHighSurrogate(c) || Character.isLowSurrogate(c)) {
if (escaped == null) {
@@ -99,8 +100,11 @@ public class JSONFilter {
if (popular > 0) {
escaped.append('\\').append(popular);
} else {
- escaped.append("\\u");
- escaped.append(String.format("%04X", Integer.valueOf(c)));
+ int v = c;
+ escaped.append("\\u").append(Character.forDigit((v >>> 12)
& 0xF, 16))
+ .append(Character.forDigit((v >>> 8) & 0xF, 16))
+ .append(Character.forDigit((v >>> 4) & 0xF, 16))
+ .append(Character.forDigit(v & 0xF, 16));
}
}
}
@@ -108,11 +112,11 @@ public class JSONFilter {
if (off == 0 && length == input.length()) {
return input;
} else {
- return input.subSequence(off, off + length);
+ return input.subSequence(off, end);
}
} else {
- if (lastUnescapedStart < off + length) {
- escaped.append(input.subSequence(lastUnescapedStart, off +
length));
+ if (lastUnescapedStart < end) {
+ escaped.append(input.subSequence(lastUnescapedStart, end));
}
return escaped.toString();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]