libyang icon indicating copy to clipboard operation
libyang copied to clipboard

When parse a xml with CDATA , a syntax error will be occured at so.ver 2.33.3 .

Open DarrinWu opened this issue 2 years ago • 3 comments

If I use libyang.so.2.33.3 and libsysrepo.7.14.20 ,with command like "sysrepocfg -d "startup" --edit=test.xml" ,there should be one syntax error occured as belows:

libyang error: Text value "<xxxx" inside an anydata node "vsData" found. (Data location "/_xxxxx/xxxx/vsDataContainer[id='1']", line number xx.)
sysrepocfg error: Data parsing failed

And the test.xml used like this:

<?xml version="1.0" encoding="UTF-8"?>
  <ME xmlns="xxxxxx">
     <Gxxxxxx>
      <vsDataContainer>
        <id>0</id>
        <vsData><![CDATA[
        <vsData>
          <gnbvs xmlns=xxxxxxx
             .........
          </gnbvs>
        </vsData>
        ]]></vsData>
      </vsDataContainer>
             .........

Indeed, I think that CDATA should be realized in function [lyxml_parse_value],and the value of ws should not returned 0 ... thanks.

DarrinWu avatar May 11 '23 18:05 DarrinWu

Our XML parser does not really support CDATA sections because they should not be needed in YANG data. Can you skip the CDATA declaration and just put the elements as standard descendants of the vsData element?

michalvasko avatar May 12 '23 06:05 michalvasko

Our XML parser does not really support CDATA sections because they should not be needed in YANG data. Can you skip the CDATA declaration and just put the elements as standard descendants of the vsData element?

I notice that the variable “ws” in CDATA process returns 0 in function 'lyxml_parse_value',which cause syntax in function 'lydxml_subtree_any' and then make sysrepo fatal. so can we comment the "ws = 0" in CDATA process and let it work? thanks!

         /* skip CDATA tag */
        in += ly_strlen_const("<![CDATA[");
        assert(!offset);

        /* analyze CDATA for non WS and newline chars */
        for (n = 0; n < u; ++n) {
            if (in[n] == '\n') {
                LY_IN_NEW_LINE(xmlctx->in);
            } else if (!is_xmlws(in[n])) {
                ws = 0; ----------------------------------just here.
            }
        }

        /* copy CDATA */
        memcpy(buf + len, in, u);
        len += u;

        /* move input skipping the end tag */
        in += u + ly_strlen_const("]]>");

DarrinWu avatar May 12 '23 07:05 DarrinWu

Sorry, so it is supported just does not work in this case. You want libyang to just ignore the contents of the CDATA? Wouldn't it make more sense to parse the nested data as the value of the anydata node? That can be fixed and is actually what happens if you skip the CDATA tag.

michalvasko avatar May 12 '23 12:05 michalvasko