toml: make value of `+nan`/`-nan` decode to `nan` (#12542)
parent
12ffe04212
commit
49cd1b3d59
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue