File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -133,13 +133,25 @@ public int hashCode() {
133133
134134 @ Override
135135 public String toString () {
136- String result = this .content ;
137- if (result .length () > 80 ) {
138- result = result .substring (0 , 80 ) + "...(truncated)" ;
136+ int maxLen = 80 ;
137+ int len = Math .min (content .length (), maxLen );
138+
139+ StringBuilder sb = new StringBuilder (len + 20 );
140+
141+ for (int i = 0 ; i < len ; i ++) {
142+ char c = content .charAt (i );
143+ switch (c ){
144+ case '\n' -> sb .append ("\\ n" );
145+ case '\r' -> sb .append ("\\ r" );
146+ default -> sb .append (c );
147+ }
139148 }
140- result = StringUtils .replace (result , "\n " , "\\ n" );
141- result = StringUtils .replace (result , "\r " , "\\ r" );
142- return "SockJsFrame content='" + result + "'" ;
149+
150+ if (content .length () > maxLen ) {
151+ sb .append ("...(truncated)" );
152+ }
153+
154+ return "SockJsFrame content='" + sb + "'" ;
143155 }
144156
145157
You can’t perform that action at this time.
0 commit comments