File tree Expand file tree Collapse file tree
src/main/java/com/muukong/protobuf Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ private ISerializable disassembleLen(int fieldNumber) {
243243 try {
244244 stringValue = decoder .decode (ByteBuffer .wrap (input , cursor , length )).toString ();
245245 // Reject strings that contain non-printable control characters
246- // (allow common whitespace: tab=0x09, LF=0x0A, CR=0x0D)
246+ // (allow common whitespace: tab=0x09, LF=0x0A, CR=0x0D — but not at the edges )
247247 isString = true ;
248248 for ( int i = 0 ; i < stringValue .length (); ++i ) {
249249 char c = stringValue .charAt (i );
@@ -252,6 +252,14 @@ private ISerializable disassembleLen(int fieldNumber) {
252252 break ;
253253 }
254254 }
255+ if ( isString && !stringValue .isEmpty () ) {
256+ char first = stringValue .charAt (0 );
257+ char last = stringValue .charAt (stringValue .length () - 1 );
258+ if ( first == '\t' || first == '\n' || first == '\r' ||
259+ last == '\t' || last == '\n' || last == '\r' ) {
260+ isString = false ;
261+ }
262+ }
255263 } catch ( CharacterCodingException e ) {
256264 isString = false ;
257265 }
You can’t perform that action at this time.
0 commit comments