File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,12 @@ pub fn parse_decimal(s: &str) -> ParseResult {
5959 let s = s. as_bytes ( ) ;
6060 let ( integral, s) = eat_digits ( s) ;
6161 match s. first ( ) {
62- None => Valid ( Decimal :: new ( integral, b"" , 0 ) ) ,
62+ None => {
63+ if integral. is_empty ( ) {
64+ return Invalid ; // No digits at all
65+ }
66+ Valid ( Decimal :: new ( integral, b"" , 0 ) )
67+ }
6368 Some ( & b'e' ) | Some ( & b'E' ) => {
6469 if integral. is_empty ( ) {
6570 return Invalid ; // No digits before 'e'
Original file line number Diff line number Diff line change @@ -101,6 +101,18 @@ fn lonely_dot() {
101101 assert_eq ! ( "." . parse( ) , Ok ( 0.0 ) ) ;
102102}
103103
104+ #[ test]
105+ fn lonely_sign ( ) {
106+ assert ! ( "+" . parse:: <f32 >( ) . is_err( ) ) ;
107+ assert ! ( "-" . parse:: <f64 >( ) . is_err( ) ) ;
108+ }
109+
110+ #[ test]
111+ fn whitespace ( ) {
112+ assert ! ( " 1.0" . parse:: <f32 >( ) . is_err( ) ) ;
113+ assert ! ( "1.0 " . parse:: <f64 >( ) . is_err( ) ) ;
114+ }
115+
104116#[ test]
105117fn nan ( ) {
106118 assert ! ( "NaN" . parse:: <f32 >( ) . unwrap( ) . is_nan( ) ) ;
You can’t perform that action at this time.
0 commit comments