Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bigint: Create the parsing error better for nested + #269

Merged
merged 2 commits into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bigint/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use std::ops::{Add, Div, Mul, Neg, Rem, Shl, Shr, Sub};
use std::str::{self, FromStr};
use std::fmt;
use std::cmp::Ordering::{self, Less, Greater, Equal};
use std::{f32, f64};
use std::{u8, i64, u64};
use std::{i64, u64};
use std::ascii::AsciiExt;

#[cfg(feature = "serde")]
Expand Down
6 changes: 4 additions & 2 deletions bigint/src/biguint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fmt;
use std::cmp;
use std::cmp::Ordering::{self, Less, Greater, Equal};
use std::{f32, f64};
use std::{u8, i64, u64};
use std::{u8, u64};
use std::ascii::AsciiExt;

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -242,7 +242,9 @@ impl Num for BigUint {
v.push(d);
} else {
// create ParseIntError::InvalidDigit
let e = u64::from_str_radix(&s[v.len()..], radix).unwrap_err();
// Include the previous character for context.
let i = cmp::max(v.len(), 1) - 1;
let e = u64::from_str_radix(&s[i..], radix).unwrap_err();
return Err(e.into());
}
}
Expand Down
2 changes: 2 additions & 0 deletions bigint/src/tests/biguint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,8 @@ fn test_from_str_radix() {
assert_eq!(plus_plus_one, None);
let minus_one = BigUint::from_str_radix("-1", 10).ok();
assert_eq!(minus_one, None);
let zero_plus_two = BigUint::from_str_radix("0+2", 10).ok();
assert_eq!(zero_plus_two, None);
}

#[test]
Expand Down