Skip to content

Commit

Permalink
Stop parsing "-" as integer, fixes #22745
Browse files Browse the repository at this point in the history
  • Loading branch information
krdln committed Feb 24, 2015
1 parent 91a5a1a commit 948a17e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libcore/num/mod.rs
Expand Up @@ -1672,6 +1672,7 @@ macro_rules! from_str_radix_int_impl {
let is_signed_ty = (0 as $T) > Int::min_value();

match src.slice_shift_char() {
Some(('-', "")) => Err(PIE { kind: Empty }),
Some(('-', src)) if is_signed_ty => {
// The number is negative
let mut result = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/libcoretest/num/mod.rs
Expand Up @@ -122,4 +122,9 @@ mod test {
assert_eq!("-9223372036854775808".parse::<i64>().ok(), Some(i64_val));
assert_eq!("-9223372036854775809".parse::<i64>().ok(), None);
}

#[test]
test_int_from_minus_sign() {
assert_eq!("-".parse::<i32>().ok(), None);
}
}

0 comments on commit 948a17e

Please sign in to comment.