From 49cd1b3d59333056431f6c932c1fc438c7e81a0c Mon Sep 17 00:00:00 2001 From: Larpon Date: Tue, 23 Nov 2021 15:23:16 +0100 Subject: [PATCH] toml: make value of `+nan`/`-nan` decode to `nan` (#12542) --- vlib/toml/ast/types.v | 3 ++- vlib/toml/decoder/decoder.v | 11 +++++++++++ vlib/toml/tests/burntsushi.toml-test_test.v | 2 -- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/vlib/toml/ast/types.v b/vlib/toml/ast/types.v index 6dffcb271b..515a7c6d2a 100644 --- a/vlib/toml/ast/types.v +++ b/vlib/toml/ast/types.v @@ -157,8 +157,9 @@ pub fn (b Bool) str() string { // Number can be integers, floats, infinite, NaN - they can have exponents (`5e2`) and be sign prefixed (`+2`). pub struct Number { pub: + pos token.Position +pub mut: text string - pos token.Position } // str returns the `string` representation of the `Number` type. diff --git a/vlib/toml/decoder/decoder.v b/vlib/toml/decoder/decoder.v index bf03918167..c3543c1dc4 100644 --- a/vlib/toml/decoder/decoder.v +++ b/vlib/toml/decoder/decoder.v @@ -30,6 +30,10 @@ fn (d Decoder) modify(mut value ast.Value) ? { mut v := &(value as ast.Quoted) d.decode_quoted(mut v) ? } + ast.Number { + mut v := &(value as ast.Number) + d.decode_number(mut v) ? + } else {} } } @@ -44,6 +48,13 @@ fn (d Decoder) decode_quoted(mut q ast.Quoted) ? { decode_quoted_escapes(mut q) ? } +// decode_number decodes the `n ast.Number` into valid TOML. +fn (d Decoder) decode_number(mut n ast.Number) ? { + if n.text == '-nan' || n.text == '+nan' { + n.text = 'nan' + } +} + // decode_quoted_escapes returns an error for any disallowed escape sequences. // Delimiters in TOML has significant meaning: // '/''' delimits *literal* strings (WYSIWYG / What-you-see-is-what-you-get) diff --git a/vlib/toml/tests/burntsushi.toml-test_test.v b/vlib/toml/tests/burntsushi.toml-test_test.v index 55e2c04cab..6bc1bd9116 100644 --- a/vlib/toml/tests/burntsushi.toml-test_test.v +++ b/vlib/toml/tests/burntsushi.toml-test_test.v @@ -17,8 +17,6 @@ const ( valid_value_exceptions = [ // Integer 'integer/long.toml', // TODO awaits BUG fix with strconv.parse_int('-9223372036854775808') - // Float - 'float/inf-and-nan.toml', // Table 'table/array-implicit.toml', // Date-time