Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug fix: strings convertable to numbers where treated as arrays. Than…
…ks to agentzh for the bug report and fix.
  • Loading branch information
Brian Maher committed Oct 26, 2010
1 parent 68448b4 commit f566e81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua_yajl.c
Expand Up @@ -744,7 +744,7 @@ static int js_generator_value(lua_State *L) {
// First iterate over the table to see if it is an array:
lua_pushnil(L);
while ( lua_next(L, 2) != 0 ) {
if ( lua_isnumber(L, -2) ) {
if ( lua_type(L, -2) == LUA_TNUMBER ) {
double num = lua_tonumber(L, -2);
if ( num == floor(num) ) {
if ( num > max ) max = num;
Expand Down
8 changes: 8 additions & 0 deletions test.lua
Expand Up @@ -13,6 +13,7 @@ function main()
null_at_end_of_array()
null_object_value()
weird_numbers()
number_in_string()
test_generator()
test_to_value()
end
Expand Down Expand Up @@ -146,4 +147,11 @@ function weird_numbers()
ok("[-0]" == got, "NaN converts to -0 (got: " .. got .. ")")
end

function number_in_string()
-- Thanks to agentzh for this bug report!
local expect = '{"2":"two"}'
local got = yajl.to_string {["2"]="two"}
ok(expect == got, expect .. " == " .. tostring(got))
end

main()

0 comments on commit f566e81

Please sign in to comment.