data: json sniff rejects '[section]' / '[[table]]' (INI / TOML no longer sniffed as JSON)

This commit is contained in:
4DBug committed 2026-10-31 08:57:25 -05:00
1 parent e11f07dade
commit b6afe0122c
1 file changed
+5
+5
View File
@@ -36,10 +36,15 @@ function JsonFormat.sniff(r: Bytes.Reader): number
local nxt = string.match(head, "^[^{]*{[ \t\r\n]*(.)") local nxt = string.match(head, "^[^{]*{[ \t\r\n]*(.)")
return if nxt == nil or nxt == '"' or nxt == "}" then 0.6 else 0.1 return if nxt == nil or nxt == '"' or nxt == "}" then 0.6 else 0.1
elseif first == "[" then elseif first == "[" then
-- past any nested '[': a JSON value must start (TOML / INI "[section]" and "[[table]]" do not)
local nxt = string.match(head, "^[ \t\r\n]*[%[ \t\r\n]*(.)")
if nxt == nil or string.find('{"-0123456789tfn]', nxt, 1, true) then
return 0.3 return 0.3
end end
return 0 return 0
end end
return 0
end
-- ------------------------------------------------------------------------------------------------ decode -- ------------------------------------------------------------------------------------------------ decode
function JsonFormat.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?) function JsonFormat.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)