You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by "coheigea (via GitHub)" <gi...@apache.org> on 2026/10/12 16:23:55 UTC
[PR] Escape control characters in JAXBToStringStyle output [cxf-xjc-utils]
coheigea opened a new pull request, #397:
URL: https://github.com/apache/cxf-xjc-utils/pull/397
toString() methods generated by the ts plugin render bean contents
through JAXBToStringStyle, so text taken from XML was copied verbatim
into log output, including CR/LF and other control characters.
Escape CR, LF, tab, other ISO control characters and U+2028/U+2029 in
String, char and QName values, including inside arrays, collections,
maps and JAXBElements. QName values are covered because a namespace
URI can carry character references such as .
Collection and map elements are routed through appendInternal so cycle
detection is kept on all commons-lang3 versions. The styles' own field
separators and the layout of collections and maps are unchanged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Escape control characters in JAXBToStringStyle output [cxf-xjc-utils]
Posted by "coheigea (via GitHub)" <gi...@apache.org>.
coheigea merged PR #397:
URL: https://github.com/apache/cxf-xjc-utils/pull/397
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Escape control characters in JAXBToStringStyle output [cxf-xjc-utils]
Posted by "coheigea (via GitHub)" <gi...@apache.org>.
coheigea commented on code in PR #397:
URL: https://github.com/apache/cxf-xjc-utils/pull/397#discussion_r4256859230
##########
runtime/src/main/java/org/apache/cxf/xjc/runtime/JAXBToStringStyle.java:
##########
@@ -77,8 +82,96 @@ class JAXBToStringStyleImpl extends ToStringStyle {
protected void appendDetail(StringBuffer buffer, String fieldName, Object value) {
if (value instanceof JAXBElement) {
buffer.append(ToStringBuilder.reflectionToString(value, this));
+ } else {
+ appendValue(buffer, value);
+ }
+ }
+
+ @Override
+ protected void appendDetail(StringBuffer buffer, String fieldName, char value) {
+ appendEscaped(buffer, String.valueOf(value));
+ }
+
+ /*
+ * Older commons-lang3 releases append collections and maps via their own
+ * toString(), which bypasses both the escaping below and cycle detection.
+ * Route each element through appendInternal instead (as commons-lang3
+ * 3.21+ does), keeping the AbstractCollection/AbstractMap layout.
+ */
+ @Override
+ protected void appendDetail(StringBuffer buffer, String fieldName, Collection<?> coll) {
+ buffer.append('[');
Review Comment:
Thanks @reta, yes it’s intentional. commons-lang3 3.21+ already does this itself: ToStringStyle.appendDetail(Collection/Map) routes each element through appendInternal, so elements get escaped and cycle-checked. Older releases just append coll.toString()/map.toString(), which bypasses both. Since commons-lang3 is an optional dependency of the runtime, the overrides copy the 3.21 behaviour so that it applies on any version. I’ve pushed a small update that makes the overrides match 3.21 exactly (separators and null map entries, with an explicit null check because appendInternal(null) throws an NPE on older releases). With 3.21, the output is now unchanged from before this PR for anything without control characters.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Escape control characters in JAXBToStringStyle output [cxf-xjc-utils]
Posted by "reta (via GitHub)" <gi...@apache.org>.
reta commented on code in PR #397:
URL: https://github.com/apache/cxf-xjc-utils/pull/397#discussion_r4253825083
##########
runtime/src/main/java/org/apache/cxf/xjc/runtime/JAXBToStringStyle.java:
##########
@@ -77,8 +82,96 @@ class JAXBToStringStyleImpl extends ToStringStyle {
protected void appendDetail(StringBuffer buffer, String fieldName, Object value) {
if (value instanceof JAXBElement) {
buffer.append(ToStringBuilder.reflectionToString(value, this));
+ } else {
+ appendValue(buffer, value);
+ }
+ }
+
+ @Override
+ protected void appendDetail(StringBuffer buffer, String fieldName, char value) {
+ appendEscaped(buffer, String.valueOf(value));
+ }
+
+ /*
+ * Older commons-lang3 releases append collections and maps via their own
+ * toString(), which bypasses both the escaping below and cycle detection.
+ * Route each element through appendInternal instead (as commons-lang3
+ * 3.21+ does), keeping the AbstractCollection/AbstractMap layout.
+ */
+ @Override
+ protected void appendDetail(StringBuffer buffer, String fieldName, Collection<?> coll) {
+ buffer.append('[');
Review Comment:
Sorry @coheigea , not very familiar with this code, but the overrides for `appendDetails` are quite different from what `ToStringStyle` produced by default, it is intentional? Thank you
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cxf.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org