File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -376,6 +376,16 @@ describe('binaryDecoderTest', function() {
376376 assertEquals ( utf8_four_bytes , decoder . readString ( utf8_four_bytes . length ) ) ;
377377 } ) ;
378378
379+ /**
380+ * Verifies that passing a non-string to writeString raises an error.
381+ */
382+ it ( 'testBadString' , function ( ) {
383+ var encoder = new jspb . BinaryEncoder ( ) ;
384+
385+ assertThrows ( function ( ) { encoder . writeString ( 42 ) } ) ;
386+ assertThrows ( function ( ) { encoder . writeString ( null ) } ) ;
387+ } ) ;
388+
379389 /**
380390 * Verifies that misuse of the decoder class triggers assertions.
381391 */
Original file line number Diff line number Diff line change @@ -473,6 +473,9 @@ jspb.BinaryEncoder.prototype.writeFixedHash64 = function(hash) {
473473jspb . BinaryEncoder . prototype . writeString = function ( value ) {
474474 var oldLength = this . buffer_ . length ;
475475
476+ // Protect against non-string values being silently ignored.
477+ goog . asserts . assertString ( value ) ;
478+
476479 for ( var i = 0 ; i < value . length ; i ++ ) {
477480
478481 var c = value . charCodeAt ( i ) ;
You can’t perform that action at this time.
0 commit comments