Skip to content

Commit c0e87f1

Browse files
committed
Make ".e0" not parse as 0.0
This forces floats to have either a digit before the separating point, or after. Thus ".e0" is invalid like ".", when using `parse()`.
1 parent 90759be commit c0e87f1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/libcore/num/dec2flt/parse.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ pub fn parse_decimal(s: &str) -> ParseResult {
7373
}
7474
Some(&b'.') => {
7575
let (fractional, s) = eat_digits(&s[1..]);
76-
if integral.is_empty() && fractional.is_empty() && s.is_empty() {
76+
if integral.is_empty() && fractional.is_empty() {
77+
// We require at least a single digit before or after the point.
7778
return Invalid;
7879
}
7980

src/libcore/tests/num/dec2flt/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ fn lonely_dot() {
101101
assert!(".".parse::<f64>().is_err());
102102
}
103103

104+
#[test]
105+
fn exponentiated_dot() {
106+
assert!(".e0".parse::<f32>().is_err());
107+
assert!(".e0".parse::<f64>().is_err());
108+
}
109+
104110
#[test]
105111
fn lonely_sign() {
106112
assert!("+".parse::<f32>().is_err());

0 commit comments

Comments
 (0)