Nmap Development mailing list archives
Re: CouchDB scripts
From: Martin Holst Swende <martin () swende se>
Date: Mon, 01 Feb 2010 19:53:29 +0100
David Fifield wrote:
I attached the debug output and packet captures. It looks like the first time, the server is returning the empty object {}, and it returns real data after that. I think your script is handling is properly, but I don't know why the server would do that. Maybe a bug?
Certainly looks so. Not seen it myself, installed afresh on an ubuntu. Probably some glitch on the couch-side.
I think you are making this more complicated than it really is. We're not parsing JavaScript, we're parsing JSON. RFC 4627, section 2, says A JSON value MUST be an object, array, number, or string, or one of the following three literal names: false null true Things like 1/2 and alert(1) are JavaScript, not JSON. In JavaScript they may return a value or whatever, but they're a syntax error for us.
Doh! Me fix.
For strings, the only escapes you have to handle are \", \\, \/, \b, \f, \n, \n, \r, \t, and \uXXXX. (I'm looking at section 2.5 of RFC 4627.) For the \uXXXX escape, I guess you should ideally collapse the character into its UTF-8 encoding. We only have 8-bit strings in NSE so Unicode text has to stay encoded. And also according to the RFC, all strings have to be quoted. The a.vax is Lua or JavaScript notation, not JSON.I like the flatten functionality, but you should make it return JSON so that the library can be used to encode as well as decode. If you just want a quick look at a Lua table, use nsedebug.tostr.It was just a quick look I wanted, so far there's no need for me to encode json. Perhaps save that for later? Thanks for the input.It's just a small modification to what you have already written. Something like: function flatten(obj) if obj == nil then return "null" elseif obj == false then return "false" elseif obj == true then return "true" elseif type(obj) == "number" then return string.format("%g", obj) elseif type(obj) == "string" then return string_escape(obj) elseif type(obj) == "table" then local k, v, elems elems = {} if #obj > 0 then -- Array for _, v in ipairs(obj) do elems[#elems + 1] = flatten(v) end return "[" .. table.concat(elems, ", ") .. "]" else -- Object for k, v in pairs(obj) do elems[#elems + 1] = string_escape(k) .. ": " .. flatten(v) end return "{" .. table.concat(elems, ", ") .. "}" end else error("Unknown data type in flatten") end end David Fifield
Sure, I'll put it in there, you already did most of the remaining work :) /Martin _______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://seclists.org/nmap-dev/
Current thread:
- Re: CouchDB and MongoDB, (continued)
- Re: CouchDB and MongoDB David Fifield (Feb 15)
- Re: CouchDB and MongoDB Martin Holst Swende (Feb 22)
- Re: CouchDB and MongoDB David Fifield (Feb 23)
- Re: CouchDB and MongoDB Martin Holst Swende (Feb 27)
- Re: CouchDB and MongoDB David Fifield (Feb 28)
- Re: CouchDB and MongoDB Patrick Donnelly (Feb 28)
- Re: CouchDB and MongoDB Martin Holst Swende (Mar 01)
- Re: CouchDB and MongoDB Patrick Donnelly (Mar 01)
- Lua and LPeg David Fifield (Mar 05)
- Re: Lua and LPeg Patrick Donnelly (Mar 05)
- Re: CouchDB scripts Martin Holst Swende (Feb 01)
- Re: MongoDB scripts David Fifield (Jan 29)