toml: make value of `+nan`/`-nan` decode to `nan` (#12542)

pull/12553/head^2
Larpon 2021-11-23 15:23:16 +01:00 committed by GitHub
parent 12ffe04212
commit 49cd1b3d59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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