On 02/03/2023 13:38, r...@apache.org wrote:
This is an automated email from the ASF dual-hosted git repository.
remm 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 50a9edfdb2 Improve JSON filter
50a9edfdb2 is described below
commit 50a9edfdb230c06de40ccc69be8fe4947ebd3fce
Author: remm <r...@apache.org>
AuthorDate: Thu Mar 2 14:38:00 2023 +0100
Improve JSON filter
Add more capabilities (filtering from a writer, as in the PR, etc). Some
common chars have a special more readable escape sequence in RFC 8259.
Based on parts of PR#539 submitted by Thomas Meyer.
---
java/org/apache/tomcat/util/json/JSONFilter.java | 104 ++++++++++++++++++---
.../apache/tomcat/util/json/TestJSONFilter.java | 35 ++++---
webapps/docs/changelog.xml | 9 ++
3 files changed, 122 insertions(+), 26 deletions(-)
diff --git a/java/org/apache/tomcat/util/json/JSONFilter.java
b/java/org/apache/tomcat/util/json/JSONFilter.java
index b5992d95d6..fe771b55cd 100644
--- a/java/org/apache/tomcat/util/json/JSONFilter.java
+++ b/java/org/apache/tomcat/util/json/JSONFilter.java
@@ -23,39 +23,119 @@ package org.apache.tomcat.util.json;
*/
public class JSONFilter {
- private JSONFilter() {
- // Utility class. Hide the default constructor.
Why remove this? We don't want instances of JSONFilter created.
<snip/>
+ /**
+ * Escape the given string.
+ * @param input the string
+ * @return the escaped string
+ */
public static String escape(String input) {
+ return escape((CharSequence) input, 0, input.length()).toString();
Unnecessary cast.
+ /**
+ * Escape the given char sequence.
+ * @param input the char sequence
+ * @param off the offset on which escaping will start
+ * @param length the length which should be escaped
+ * @return the escaped char sequence corresponding to the specified range
+ */
+ public static CharSequence escape(CharSequence input, int off, int length)
{
/*
* While any character MAY be escaped, only U+0000 to U+001F (control
* characters), U+0022 (quotation mark) and U+005C (reverse solidus)
* MUST be escaped.
*/
- char[] chars = input.toCharArray();
+ //char[] chars = input.toCharArray();
Should be removed rather than commented out.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org