@@ -380,7 +380,14 @@ impl<'de, R: Read<'de>> Deserializer<R> {
380
380
}
381
381
382
382
fn parse_integer ( & mut self , positive : bool ) -> Result < ParserNumber > {
383
- match try!( self . next_char_or_null ( ) ) {
383
+ let next = match try!( self . next_char ( ) ) {
384
+ Some ( b) => b,
385
+ None => {
386
+ return Err ( self . error ( ErrorCode :: EofWhileParsingValue ) ) ;
387
+ }
388
+ } ;
389
+
390
+ match next {
384
391
b'0' => {
385
392
// There can be only one leading '0'.
386
393
match try!( self . peek_or_null ( ) ) {
@@ -496,7 +503,10 @@ impl<'de, R: Read<'de>> Deserializer<R> {
496
503
}
497
504
498
505
if !at_least_one_digit {
499
- return Err ( self . peek_error ( ErrorCode :: InvalidNumber ) ) ;
506
+ match try!( self . peek ( ) ) {
507
+ Some ( _) => return Err ( self . peek_error ( ErrorCode :: InvalidNumber ) ) ,
508
+ None => return Err ( self . peek_error ( ErrorCode :: EofWhileParsingValue ) ) ,
509
+ }
500
510
}
501
511
502
512
match try!( self . peek_or_null ( ) ) {
@@ -525,8 +535,15 @@ impl<'de, R: Read<'de>> Deserializer<R> {
525
535
_ => true ,
526
536
} ;
527
537
538
+ let next = match try!( self . next_char ( ) ) {
539
+ Some ( b) => b,
540
+ None => {
541
+ return Err ( self . error ( ErrorCode :: EofWhileParsingValue ) ) ;
542
+ }
543
+ } ;
544
+
528
545
// Make sure a digit follows the exponent place.
529
- let mut exp = match try! ( self . next_char_or_null ( ) ) {
546
+ let mut exp = match next {
530
547
c @ b'0' ...b'9' => ( c - b'0' ) as i32 ,
531
548
_ => {
532
549
return Err ( self . error ( ErrorCode :: InvalidNumber ) ) ;
@@ -623,19 +640,19 @@ impl<'de, R: Read<'de>> Deserializer<R> {
623
640
}
624
641
625
642
#[ cfg( feature = "arbitrary_precision" ) ]
626
- fn scan_or_null ( & mut self , buf : & mut String ) -> Result < u8 > {
643
+ fn scan_or_eof ( & mut self , buf : & mut String ) -> Result < u8 > {
627
644
match try!( self . next_char ( ) ) {
628
645
Some ( b) => {
629
646
buf. push ( b as char ) ;
630
647
Ok ( b)
631
648
}
632
- None => Ok ( b'\x00' ) ,
649
+ None => Err ( self . error ( ErrorCode :: EofWhileParsingValue ) )
633
650
}
634
651
}
635
652
636
653
#[ cfg( feature = "arbitrary_precision" ) ]
637
654
fn scan_integer ( & mut self , buf : & mut String ) -> Result < ( ) > {
638
- match try!( self . scan_or_null ( buf) ) {
655
+ match try!( self . scan_or_eof ( buf) ) {
639
656
b'0' => {
640
657
// There can be only one leading '0'.
641
658
match try!( self . peek_or_null ( ) ) {
@@ -680,7 +697,10 @@ impl<'de, R: Read<'de>> Deserializer<R> {
680
697
}
681
698
682
699
if !at_least_one_digit {
683
- return Err ( self . peek_error ( ErrorCode :: InvalidNumber ) ) ;
700
+ match try!( self . peek ( ) ) {
701
+ Some ( _) => return Err ( self . peek_error ( ErrorCode :: InvalidNumber ) ) ,
702
+ None => return Err ( self . peek_error ( ErrorCode :: EofWhileParsingValue ) ) ,
703
+ }
684
704
}
685
705
686
706
match try!( self . peek_or_null ( ) ) {
@@ -706,7 +726,7 @@ impl<'de, R: Read<'de>> Deserializer<R> {
706
726
}
707
727
708
728
// Make sure a digit follows the exponent place.
709
- match try!( self . scan_or_null ( buf) ) {
729
+ match try!( self . scan_or_eof ( buf) ) {
710
730
b'0' ...b'9' => { }
711
731
_ => {
712
732
return Err ( self . error ( ErrorCode :: InvalidNumber ) ) ;
0 commit comments