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`).
|
// Number can be integers, floats, infinite, NaN - they can have exponents (`5e2`) and be sign prefixed (`+2`).
|
||||||
pub struct Number {
|
pub struct Number {
|
||||||
pub:
|
pub:
|
||||||
|
pos token.Position
|
||||||
|
pub mut:
|
||||||
text string
|
text string
|
||||||
pos token.Position
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// str returns the `string` representation of the `Number` type.
|
// 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)
|
mut v := &(value as ast.Quoted)
|
||||||
d.decode_quoted(mut v) ?
|
d.decode_quoted(mut v) ?
|
||||||
}
|
}
|
||||||
|
ast.Number {
|
||||||
|
mut v := &(value as ast.Number)
|
||||||
|
d.decode_number(mut v) ?
|
||||||
|
}
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +48,13 @@ fn (d Decoder) decode_quoted(mut q ast.Quoted) ? {
|
||||||
decode_quoted_escapes(mut q) ?
|
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.
|
// decode_quoted_escapes returns an error for any disallowed escape sequences.
|
||||||
// Delimiters in TOML has significant meaning:
|
// Delimiters in TOML has significant meaning:
|
||||||
// '/''' delimits *literal* strings (WYSIWYG / What-you-see-is-what-you-get)
|
// '/''' delimits *literal* strings (WYSIWYG / What-you-see-is-what-you-get)
|
||||||
|
|
|
@ -17,8 +17,6 @@ const (
|
||||||
valid_value_exceptions = [
|
valid_value_exceptions = [
|
||||||
// Integer
|
// Integer
|
||||||
'integer/long.toml', // TODO awaits BUG fix with strconv.parse_int('-9223372036854775808')
|
'integer/long.toml', // TODO awaits BUG fix with strconv.parse_int('-9223372036854775808')
|
||||||
// Float
|
|
||||||
'float/inf-and-nan.toml',
|
|
||||||
// Table
|
// Table
|
||||||
'table/array-implicit.toml',
|
'table/array-implicit.toml',
|
||||||
// Date-time
|
// Date-time
|
||||||
|
|
Loading…
Reference in New Issue