diff options
author | Nadrieril | 2019-03-23 13:45:54 +0100 |
---|---|---|
committer | Nadrieril | 2019-03-23 13:45:54 +0100 |
commit | 120970ccd70b1e8eb3867fc2b511c1967eaaabbb (patch) | |
tree | 3b30a7e7b72351745cbfe81f50911b9defb5d482 /dhall | |
parent | 4a45ed7e1f80a7d3e4032e08eb499dab3412453f (diff) |
Handle double overflows in parser
Diffstat (limited to '')
-rw-r--r-- | dhall/tests/parser.rs | 4 | ||||
-rw-r--r-- | dhall_core/src/parser.rs | 13 |
2 files changed, 11 insertions, 6 deletions
diff --git a/dhall/tests/parser.rs b/dhall/tests/parser.rs index f983b8c..df012d5 100644 --- a/dhall/tests/parser.rs +++ b/dhall/tests/parser.rs @@ -61,8 +61,8 @@ parser_success!(spec_parser_success_whitespace, "whitespace"); parser_success!(spec_parser_success_whitespaceBuffet, "whitespaceBuffet"); parser_failure!(spec_parser_failure_annotation, "annotation"); -// parser_failure!(spec_parser_failure_doubleBoundsNeg, "doubleBoundsNeg"); -// parser_failure!(spec_parser_failure_doubleBoundsPos, "doubleBoundsPos"); +parser_failure!(spec_parser_failure_doubleBoundsNeg, "doubleBoundsNeg"); +parser_failure!(spec_parser_failure_doubleBoundsPos, "doubleBoundsPos"); parser_failure!(spec_parser_failure_importAccess, "importAccess"); parser_failure!(spec_parser_failure_incompleteIf, "incompleteIf"); parser_failure!(spec_parser_failure_mandatoryNewline, "mandatoryNewline"); diff --git a/dhall_core/src/parser.rs b/dhall_core/src/parser.rs index 9fd3213..9b73bfd 100644 --- a/dhall_core/src/parser.rs +++ b/dhall_core/src/parser.rs @@ -355,10 +355,15 @@ make_parser! { rule!(double_literal_raw<core::Double>; raw_pair!(pair) => { - pair.as_str().trim() - .parse::<f64>() - .map(NaiveDouble::from) - .map_err(|e: std::num::ParseFloatError| custom_parse_error(&pair, format!("{}", e)))? + let s = pair.as_str().trim(); + match s.parse::<f64>() { + Ok(x) if x.is_infinite() => + Err(custom_parse_error(&pair, + format!("Overflow while parsing double literal '{}'", s) + ))?, + Ok(x) => NaiveDouble::from(x), + Err(e) => Err(custom_parse_error(&pair, format!("{}", e)))?, + } } ); |