This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new fdf9a1edcd Align JSON filter implementations.
fdf9a1edcd is described below
commit fdf9a1edcd7cd21423ab773a525db6cb23bfc5c9
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 ba909cccab..329444d1d8 100644
--- a/java/org/apache/juli/JsonFormatter.java
+++ b/java/org/apache/juli/JsonFormatter.java
@@ -163,13 +163,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));
}
}
}
@@ -210,6 +207,5 @@ public class JsonFormatter extends OneLineFormatter {
return 0;
}
}
-
}
}
diff --git a/java/org/apache/tomcat/util/json/JSONFilter.java
b/java/org/apache/tomcat/util/json/JSONFilter.java
index 11710f1bee..14f8e85f0e 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]