manoelcampos / xml2lua

XML Parser written entirely in Lua that works for Lua 5.1+. Convert XML to and from Lua Tables πŸŒ–πŸ’±
MIT License
287 stars 73 forks source link

Spurious indenting when putting a table in a table #81

Closed JJTech0130 closed 1 year ago

JJTech0130 commented 2 years ago

I'm trying to serialize an XML document that has a table inside a table, like this:

local tb = {
    _attr = { requestType = "Initial"},
    fingerprint = fingerprint,
    deviceType = "standalone",
    clientOS = "Windows 8", -- TODO: make this configurable
    clientLocale = "en",
    clientVersion = "2.0.1.78765", -- TODO: make this configurable
    targetDevice = {
        softwareVersion = "9.3.58046",
        clientOS = "Windows 8", -- TODO: make this configurable
        clientLocale = "en",
        clientVersion = "2.0.1.78765", -- TODO: make this configurable
        deviceType = "standalone",
        productName = "ADOBE Digitial Editions", -- [sic] Yes, the real ADE misspells Digital...
        fingerprint = fingerprint,
    },
    nonce = crypto.nonce(),
    expiration = util.expiration(10), -- 10 minutes
    user = user
}
-- serialize it

and I get something like this:

<activate requestType="Initial">
  <clientVersion>2.0.1.78765</clientVersion>
    <targetDevice>
      <clientVersion>2.0.1.78765</clientVersion>
      <productName>ADOBE Digitial Editions</productName>
      <deviceType>standalone</deviceType>
      <clientOS>Windows 8</clientOS>
      <fingerprint>Gp6IvTeq2pzVJs3cY5VsK20p84E=</fingerprint>
      <clientLocale>en</clientLocale>
      <softwareVersion>9.3.58046</softwareVersion>
    </targetDevice>
    <nonce>Pj/Wyl7jV/ixaXD3</nonce>
    <expiration>2022-07-11T21:47:24Z</expiration>
    <fingerprint>Gp6IvTeq2pzVJs3cY5VsK20p84E=</fingerprint>
    <deviceType>standalone</deviceType>
    <clientOS>Windows 8</clientOS>
    <user>urn:uuid:ef4cf545-465e-43ee-96dd-c8ec33d2937e</user>
    <clientLocale>en</clientLocale>
</activate>

See how targetDevice and everything after it is indented?

This seems to be caused by https://github.com/manoelcampos/xml2lua/blob/master/xml2lua.lua#L220, and after I removed it the issue is indeed resolved.

I'm hesitant to simply include that change in my project, though, because I am unaware of any side-effects it might have.

manoelcampos commented 2 years ago

I see. I have to check but and I'm on vacation. Anyway, indentation is just formatting and doesn't cause and parse issues.

JJTech0130 commented 2 years ago

I know, it just makes it look weird πŸ˜„, so I thought I'd report it. I'm modifying it quite a bit already, to add hacks for namespaces and sorting (for signing), so I'll include the change in my version. (I tested this with an unmodified version, though) Doesn't seem to cause any harm so far, but I'll report here if I notice anything.