xmlToJson Issue

Issue #11 resolved
Danny Roessner created an issue

There is an issue parsing xml output from an sql query using xmlToJson in certain cases.

For example, my query raw response is:

<?xml version='1.0'?><myscript><sql>
<query error='fast' conn='conn1' stmt='stmt1'>
<success><![CDATA[+++ success *query here*]]></success>
</query>
<fetch block='all' desc='on' stmt='stmt1'>
<row><data desc='SPCDEC'></data><data desc='SPCCNT'>0</data></row>
<row><data desc='SPCDEC'></data><data desc='SPCCNT'>0</data></row>
<row><data desc='SPCDEC'></data><data desc='SPCCNT'>0</data></row>
<row><data desc='SPCDEC'></data><data desc='SPCCNT'>0</data></row>
<success>+++ success stmt1</success>
</fetch>
</sql>
</myscript>

xmlToJson output:

[ [ { desc: 'SPCDEC', value: '</data><data desc=\'SPCCNT\'>0' } ],
  [ { desc: 'SPCDEC', value: '</data><data desc=\'SPCCNT\'>0' } ],
  [ { desc: 'SPCDEC', value: '</data><data desc=\'SPCCNT\'>0' } ],
  [ { desc: 'SPCDEC', value: '</data><data desc=\'SPCCNT\'>0' } ] ]

It looks like there is a bug in the sql row regex.

Suggesting changing lines 45-46 in itoolkit.js to:

  var sqlRowG = /<data desc='[\s\S]+?'>[\s\S]*?<\/data>/g;
  var sqlRow = /<data desc='([\s\S]+?)'>([\s\S]*?)<\/data>/;

This fixed the issue for my case.

Comments (6)

  1. Aaron Bartell

    Thanks for reporting this, @droessner.

    Do you know how to do forks and pull requests? And if so, could you create a pull request that includes both the fix and a new unit test?

  2. Aaron Bartell

    @droessner, this is perfect! Thanks.

    The unit test passed for me. I will Approve this pull request.

    Approving PRs

    @mengxumx and @rangercairns, how do you want to do approvals of pull requests? For now I propose we each click the Approve button on the PR page and once we have all core committers signing off on the change we can merge. Thoughts?

    How to test PRs

    On final note, here's a brief tutorial on how to test this pull request.

  3. Former user Account Deleted

    how do you want to do approvals of pull requests?

    I consider you an equal partner. In fact, equal administrator of this project. Therefore, you may commit anything you like. However, I am speaking only for myself, not Xu Meng.

  4. Log in to comment