summaryrefslogtreecommitdiff
path: root/relaxng.c
diff options
context:
space:
mode:
authorNikolai Weibull <now@disu.se>2018-10-12 23:46:24 +0200
committerDaniel Veillard <veillard@redhat.com>2018-11-29 21:03:11 +0100
commit46da8fc5290ed3243d0c137d712a1ed05c489f5f (patch)
tree085dcfc403b682ad40c7104447e86058dea5c255 /relaxng.c
parent4338c310eb5e9402d0d4bf1cdf6d60430ac8a9a8 (diff)
downloadlibxml2-46da8fc5290ed3243d0c137d712a1ed05c489f5f.tar.gz
Allow choice within choice in nameClass in RELAX NG
The pattern nameClass allows for nested choice elements, for example <name> <choice> <choice> <name>a</name> <name>b</name> </choice> <name>c</name> </choice> </name> which is semantically equivalent to <name> <choice> <name>a</name> <name>b</name> <name>c</name> </choice> </name> The old code didn’t handle this correctly, as it never expected a choice inside another choice. This patch fixes this by flattening any nested choices. This pattern of nested choice elements comes up in RELAX NG simplification, where all choice elements are rewritten in this nested manner, see section 4.12 of the RELAX NG specification.
Diffstat (limited to 'relaxng.c')
-rw-r--r--relaxng.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/relaxng.c b/relaxng.c
index a3088cbd..8725444b 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -5363,11 +5363,15 @@ xmlRelaxNGParseNameClass(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node,
xmlNodePtr child;
xmlRelaxNGDefinePtr last = NULL;
- ret = xmlRelaxNGNewDefine(ctxt, node);
- if (ret == NULL)
- return (NULL);
- ret->parent = def;
- ret->type = XML_RELAXNG_CHOICE;
+ if (def->type == XML_RELAXNG_CHOICE) {
+ ret = def;
+ } else {
+ ret = xmlRelaxNGNewDefine(ctxt, node);
+ if (ret == NULL)
+ return (NULL);
+ ret->parent = def;
+ ret->type = XML_RELAXNG_CHOICE;
+ }
if (node->children == NULL) {
xmlRngPErr(ctxt, node, XML_RNGP_CHOICE_EMPTY,
@@ -5379,7 +5383,7 @@ xmlRelaxNGParseNameClass(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node,
tmp = xmlRelaxNGParseNameClass(ctxt, child, ret);
if (tmp != NULL) {
if (last == NULL) {
- last = ret->nameClass = tmp;
+ last = tmp;
} else {
last->next = tmp;
last = tmp;