xml parser BUGFIX restore parser after skipping attributes
Fixes cesnet/netopeer2#915
@@ -340,7 +340,11 @@ lydxml_data_check_opaq(struct lyd_xml_ctx *lydctx, const struct lysc_node **snod
return LY_SUCCESS;
}
- if ((*snode)->nodetype & (LYD_NODE_TERM | LYS_LIST)) {
+ if (!((*snode)->nodetype & (LYD_NODE_TERM | LYD_NODE_INNER))) {
+ /* nothing to check */
+ return LY_SUCCESS;
+ }
+
/* backup parser */
prev_status = xmlctx->status;
pprefix = xmlctx->prefix;
@@ -364,7 +368,7 @@ lydxml_data_check_opaq(struct lyd_xml_ctx *lydctx, const struct lysc_node **snod
if (lys_value_validate(NULL, *snode, xmlctx->value, xmlctx->value_len, LY_VALUE_XML, &xmlctx->ns)) {
*snode = NULL;
}
- } else {
+ } else if ((*snode)->nodetype == LYS_LIST) {
/* skip content */
LY_CHECK_GOTO(ret = lyxml_ctx_next(xmlctx), restore);
@@ -372,6 +376,12 @@ lydxml_data_check_opaq(struct lyd_xml_ctx *lydctx, const struct lysc_node **snod
/* invalid list, parse as opaque if it missing/has invalid some keys */
*snode = NULL;
}
+ } else {
+ /* if there is a non-WS value, it cannot be parsed as an inner node */
+ assert(xmlctx->status == LYXML_ELEM_CONTENT);
+ if (!xmlctx->ws_only) {
+ *snode = NULL;
+ }
}
restore:
@@ -385,20 +395,6 @@ restore:
xmlctx->name = pname;
xmlctx->name_len = pname_len;
xmlctx->in->current = prev_current;
- } else if ((*snode)->nodetype & LYD_NODE_INNER) {
- /* skip attributes */
- while (xmlctx->status == LYXML_ATTRIBUTE) {
- LY_CHECK_RET(lyxml_ctx_next(xmlctx));
- LY_CHECK_RET(lyxml_ctx_next(xmlctx));
- }
-
- /* if there is a non-WS value, it cannot be parsed as an inner node */
- assert(xmlctx->status == LYXML_ELEM_CONTENT);
- if (!xmlctx->ws_only) {
- *snode = NULL;
- }
-
- }
return ret;
}
