Commit 3de36e2
committed
fix(toml): handle Infinity/NaN and Date in inline arrays
Inline array stringification used JSON.stringify, which silently turned
Infinity/-Infinity/NaN into 'null' and wrapped Date values in extra
quotes. Both forms broke round-trip through parse():
stringify({x: [Infinity, -Infinity, NaN]}) // x = [null,null,null]
stringify({x: [new Date(0)]}) // x = ["1970-01-01..."]
The same flaw affected #printAsInlineValue, which was the path for
mixed-type arrays — Date values were quoted and non-finite numbers
fell through as String(Infinity) / String(NaN).
Replace the JSON.stringify call in #arrayDeclaration with a per-element
walk through #printAsInlineValue, and teach #printAsInlineValue to emit
TOML's inf / -inf / nan keywords for non-finite numbers and to leave
Date values unquoted to match TOML's datetime literal syntax.
The 'handles mixed array' test pinned the buggy
date = "2022-05-13T00:00:00.000" form inside a nested inline map.
Updated to the correct unquoted form. Four new tests pin the issue's
specific repros (primitive Infinity/-Infinity/NaN, primitive Date,
mixed inf/nan/object, mixed date/object).
Fixes #7162 (partially — the null-in-array cases are left for a
follow-up since the spec disallows null in TOML and the right behavior
is a separate design call).1 parent cdf74a8 commit 3de36e2
2 files changed
Lines changed: 62 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
138 | 141 | | |
139 | 142 | | |
140 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
141 | 150 | | |
142 | 151 | | |
143 | 152 | | |
| |||
185 | 194 | | |
186 | 195 | | |
187 | 196 | | |
188 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
189 | 203 | | |
190 | 204 | | |
191 | 205 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| 240 | + | |
| 241 | + | |
240 | 242 | | |
241 | 243 | | |
242 | 244 | | |
243 | | - | |
| 245 | + | |
244 | 246 | | |
245 | 247 | | |
246 | 248 | | |
| |||
275 | 277 | | |
276 | 278 | | |
277 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
0 commit comments