Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

got two question about determine the type of 'number' #11

Open
aoaoluming opened this issue Mar 23, 2017 · 1 comment
Open

got two question about determine the type of 'number' #11

aoaoluming opened this issue Mar 23, 2017 · 1 comment

Comments

@aoaoluming
Copy link

aoaoluming commented Mar 23, 2017

when i test xml lib ,i got two question;

the first one:

local xml = require "xml"
local tb = {str='test',num=11}
local data = xml.dump(tb)

then i got this error:

lua: /usr/local/share/lua/5.3/xml/init.lua:142: attempt to index a number value (local 'v')
stack traceback:
	/usr/local/share/lua/5.3/xml/init.lua:142: in upvalue 'escape'
	/usr/local/share/lua/5.3/xml/init.lua:150: in upvalue 'tagWithAttributes'
	/usr/local/share/lua/5.3/xml/init.lua:182: in upvalue 'doDump'
	/usr/local/share/lua/5.3/xml/init.lua:195: in function 'xml.dump'
	test.lua:25: in main chunk
	[C]: in ?

i think you need to determine number type in init.lua L142

  elseif type(v) == 'number' then
	return tostring(v)
  else
    return v:gsub('&','&amp;'):gsub('>','&gt;'):gsub('<','&lt;'):gsub("'",'&apos;')
  end

the second :

when i encode this table:

local xml = require "xml"
local tb = {xml='xml',{xml='str','test'},{xml='num',33}}
print(xml.dump(tb))

i found that there is an unnecessary '\n' after the number 33, like this:

<xml>
  <str>test</str>
  <num>33
  </num>
</xml>

fixed by this:

--init.lua line175,  local function doDump  
...
elseif typ == 'number' then
  insert(output, tostring(child))
  last = 's'       --add this code to escape 'indent'
else
...
  • Hope this email finds you well.
@gaspard
Copy link
Member

gaspard commented Apr 4, 2017

Hi there, thanks for the detailed review.

I have moved away from Lua but will try to fix this and release a fix. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants