Skip to content

Commit 3597351

Browse files
authored
Fix scientific floats (#774)
1 parent 65aee42 commit 3597351

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/input/parse_json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'de> Deserialize<'de> for JsonInput {
146146

147147
if let JsonInput::String(s) = &first_value {
148148
// Normalize the string to either an int or float
149-
let normalized = if s.contains('.') {
149+
let normalized = if s.contains('.') || s.contains('e') {
150150
JsonInput::Float(
151151
s.parse()
152152
.map_err(|e| V::Error::custom(format!("expected a float: {e}")))?,

tests/validators/test_float.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,9 @@ def test_non_finite_constrained_float_values(input_value, allow_inf_nan, expecte
325325
v.validate_python(input_value)
326326
else:
327327
assert v.validate_python(input_value) == expected
328+
329+
330+
def test_validate_scientific_notation_from_json():
331+
v = SchemaValidator({'type': 'float'})
332+
assert v.validate_json('1.0e-12') == 1e-12
333+
assert v.validate_json('1e-12') == 1e-12

0 commit comments

Comments
 (0)