Permalink
Browse files

Fix SAX2 builder in case of undefined element namespaces

Work as in XML-1.0 before namespaces, and use prefix:localname
as the new element name (and no namespace of course)
Also fix 3 cases in the regression tests where the prefix: was
erroneously dropped in such case
  • Loading branch information...
1 parent b8428a2 commit 77b77b1301e052d90e6a0967534a698506afcd86 @veillard veillard committed Jan 26, 2012
Showing with 26 additions and 5 deletions.
  1. +23 −2 SAX2.c
  2. +1 −1 result/namespaces/err_7.xml
  3. +1 −1 result/xmlid/id_tst2.xml
  4. +1 −1 result/xmlid/id_tst3.xml
View
25 SAX2.c
@@ -2163,6 +2163,7 @@ xmlSAX2StartElementNs(void *ctx,
xmlNodePtr parent;
xmlNsPtr last = NULL, ns;
const xmlChar *uri, *pref;
+ xmlChar *lname = NULL;
int i, j;
if (ctx == NULL) return;
@@ -2182,6 +2183,20 @@ xmlSAX2StartElementNs(void *ctx,
}
/*
+ * Take care of the rare case of an undefined namespace prefix
+ */
+ if ((prefix != NULL) && (URI == NULL)) {
+ if (ctxt->dictNames) {
+ const xmlChar *fullname;
+
+ fullname = xmlDictQLookup(ctxt->dict, prefix, localname);
+ if (fullname != NULL)
+ localname = fullname;
+ } else {
+ lname = xmlBuildQName(localname, prefix, NULL, 0);
+ }
+ }
+ /*
* allocate the node
*/
if (ctxt->freeElems != NULL) {
@@ -2194,7 +2209,10 @@ xmlSAX2StartElementNs(void *ctx,
if (ctxt->dictNames)
ret->name = localname;
else {
- ret->name = xmlStrdup(localname);
+ if (lname == NULL)
+ ret->name = xmlStrdup(localname);
+ else
+ ret->name = lname;
if (ret->name == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
return;
@@ -2206,8 +2224,11 @@ xmlSAX2StartElementNs(void *ctx,
if (ctxt->dictNames)
ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,
(xmlChar *) localname, NULL);
- else
+ else if (lname == NULL)
ret = xmlNewDocNode(ctxt->myDoc, NULL, localname, NULL);
+ else
+ ret = xmlNewDocNodeEatName(ctxt->myDoc, NULL,
+ (xmlChar *) lname, NULL);
if (ret == NULL) {
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartElementNs");
return;
@@ -1,2 +1,2 @@
<?xml version="1.0"?>
-<foo/>
+<f:foo/>
View
@@ -1,6 +1,6 @@
Object is a Node Set :
Set contains 1 nodes:
-1 ELEMENT foo
+1 ELEMENT n:foo
ATTRIBUTE id
TEXT
content=bar
View
@@ -1,6 +1,6 @@
Object is a Node Set :
Set contains 1 nodes:
-1 ELEMENT o:o
+1 ELEMENT f:o:o
ATTRIBUTE id
TEXT
content=bar

0 comments on commit 77b77b1

Please sign in to comment.