File tree 2 files changed +18
-1
lines changed
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 {
59
59
let s = s. as_bytes ( ) ;
60
60
let ( integral, s) = eat_digits ( s) ;
61
61
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
+ }
63
68
Some ( & b'e' ) | Some ( & b'E' ) => {
64
69
if integral. is_empty ( ) {
65
70
return Invalid ; // No digits before 'e'
Original file line number Diff line number Diff line change @@ -101,6 +101,18 @@ fn lonely_dot() {
101
101
assert_eq ! ( "." . parse( ) , Ok ( 0.0 ) ) ;
102
102
}
103
103
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
+
104
116
#[ test]
105
117
fn nan ( ) {
106
118
assert ! ( "NaN" . parse:: <f32 >( ) . unwrap( ) . is_nan( ) ) ;
You can’t perform that action at this time.
0 commit comments