summaryrefslogtreecommitdiff
path: root/crates/gipfel-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/gipfel-core/src')
-rw-r--r--crates/gipfel-core/src/hill.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/crates/gipfel-core/src/hill.rs b/crates/gipfel-core/src/hill.rs
index 4ae0f89..254a9e4 100644
--- a/crates/gipfel-core/src/hill.rs
+++ b/crates/gipfel-core/src/hill.rs
@@ -67,6 +67,9 @@ fn atof(s: &str) -> f64 {
return v;
}
for i in (1..s.len()).rev() {
+ if !s.is_char_boundary(i) {
+ continue;
+ }
if let Ok(v) = s[..i].parse::<f64>() {
return v;
}
@@ -163,6 +166,8 @@ mod tests {
assert_eq!(atof("abc"), 0.0);
assert_eq!(atof("12abc"), 12.0);
assert_eq!(atof(" -3.5x"), -3.5);
+ // prefix cut must not slice through a multi-byte character
+ assert_eq!(atof("12.5\u{b0}"), 12.5);
}
#[test]