diff options
author | pommicket <pommicket@gmail.com> | 2025-09-09 13:59:20 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-09-09 13:59:20 -0400 |
commit | 8d2b61549d4c5924345e93130b50499b35db9ccb (patch) | |
tree | 7c0cd72ba77de290d9fadc168010b4cd18e14404 | |
parent | 2b8fab93d8006de1f570d72c78c96ab9a1785724 (diff) |
Check for bad decimal locations
-rw-r--r-- | src/lib.rs | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -248,6 +248,15 @@ fn parse_float(location: &Location, string: &str) -> Result<f64> { }) { return Err(bad_float()); } + for (i, c) in string.bytes().enumerate() { + if c == b'.' { + // decimal point must be preceded and followed by a digit + let ok = |j| string.as_bytes().get(j).is_some_and(u8::is_ascii_digit); + if !(ok(i.wrapping_sub(1)) && ok(i + 1)) { + return Err(bad_float()); + } + } + } string.parse().map_err(|_| bad_float()) } |