Skip to content

Commit 36ce855

Browse files
committed
改进错误信息
1 parent 4aede8e commit 36ce855

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

json.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,16 @@ if string_match(tostring(1 / 2), "%p") == "," then
145145
end
146146

147147
function encode_map.number(v)
148+
if math_type(v) == "integer" then
149+
return string_format("%d", v)
150+
end
148151
if v ~= v then
149152
error("NaN is not supported in JSON")
150-
elseif v <= tiny or v >= huge then
153+
elseif v <= tiny then
154+
error("-Inf is not supported in JSON")
155+
elseif v >= huge then
151156
error("Inf is not supported in JSON")
152157
end
153-
if math_type(v) == "integer" then
154-
return string_format("%d", v)
155-
end
156158
return convertreal(v)
157159
end
158160

test/conformance.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ function other.encode_sparse_array()
131131
lt.assertEquals(json.encode { 1, 2 }, "[1,2]")
132132
lt.assertError(json.encode, { nil, 2 })
133133
lt.assertError(json.encode, { 1, 2, nil, 4 })
134-
lt.assertError(json.encode, { 1, 2,[100] = 1 })
134+
lt.assertError(json.encode, { 1, 2, [100] = 1 })
135135
lt.assertError(json.encode, { 1, 2, a = 1 })
136-
lt.assertError(json.encode, { 1, 2,[0] = 1 })
136+
lt.assertError(json.encode, { 1, 2, [0] = 1 })
137137
json.supportSparseArray = true
138138
lt.assertEquals(json.encode { nil, 1 }, "[null,1]")
139139
end

0 commit comments

Comments
 (0)