Skip to content

Commit

Permalink
Auto merge of #29050 - rkruppe:dec2flt-lonely-sign, r=alexcrichton
Browse files Browse the repository at this point in the history
Fixes #29042
  • Loading branch information
bors committed Oct 15, 2015
2 parents 7ac89d2 + 71dcd7f commit be3d390
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libcore/num/dec2flt/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ pub fn parse_decimal(s: &str) -> ParseResult {
let s = s.as_bytes();
let (integral, s) = eat_digits(s);
match s.first() {
None => Valid(Decimal::new(integral, b"", 0)),
None => {
if integral.is_empty() {
return Invalid; // No digits at all
}
Valid(Decimal::new(integral, b"", 0))
}
Some(&b'e') | Some(&b'E') => {
if integral.is_empty() {
return Invalid; // No digits before 'e'
Expand Down
12 changes: 12 additions & 0 deletions src/libcoretest/num/dec2flt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ fn lonely_dot() {
assert_eq!(".".parse(), Ok(0.0));
}

#[test]
fn lonely_sign() {
assert!("+".parse::<f32>().is_err());
assert!("-".parse::<f64>().is_err());
}

#[test]
fn whitespace() {
assert!(" 1.0".parse::<f32>().is_err());
assert!("1.0 ".parse::<f64>().is_err());
}

#[test]
fn nan() {
assert!("NaN".parse::<f32>().unwrap().is_nan());
Expand Down

0 comments on commit be3d390

Please sign in to comment.