summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-11-06 06:37:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-11-06 06:38:11 +0000
commit0c8553db3836cf0f9e8731817d713e37db55195f (patch)
treed434aa3a3d496d7ca21323f21181d55652022fea
parentReleasing progress-linux version 0.4.8-1~progress5+u1. (diff)
downloadhtml5-parser-0c8553db3836cf0f9e8731817d713e37db55195f.tar.xz
html5-parser-0c8553db3836cf0f9e8731817d713e37db55195f.zip
Merging upstream version 0.4.9.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r--src/as-libxml.c28
-rw-r--r--src/python-wrapper.c2
-rw-r--r--test/namespace.py9
3 files changed, 25 insertions, 14 deletions
diff --git a/src/as-libxml.c b/src/as-libxml.c
index dee4156..2bcb6ba 100644
--- a/src/as-libxml.c
+++ b/src/as-libxml.c
@@ -50,14 +50,25 @@ push_children(xmlNodePtr parent, GumboElement *elem, Stack *stack) {
static inline xmlNsPtr
ensure_xml_ns(xmlDocPtr doc, ParseData *pd, xmlNodePtr node) {
// By default libxml2 docs do not have the xml: namespace defined.
- xmlNodePtr root = pd->root ? pd->root : node;
if (UNLIKELY(!pd->xml)) {
+ xmlNodePtr root = pd->root ? pd->root : node;
pd->xml = xmlSearchNs(doc, root, BAD_CAST "xml");
}
return pd->xml;
}
static inline xmlNsPtr
+ensure_xlink_ns(xmlDocPtr doc, ParseData *pd, xmlNodePtr node) {
+ if (UNLIKELY(!pd->xlink)) {
+ xmlNodePtr root = pd->root ? pd->root : node;
+ pd->xlink = xmlSearchNs(doc, root, BAD_CAST "xlink");
+ if (UNLIKELY(!pd->xlink)) pd->xlink = xmlNewNs(root, BAD_CAST "http://www.w3.org/1999/xlink", BAD_CAST "xlink");
+ }
+ return pd->xlink;
+}
+
+
+static inline xmlNsPtr
find_namespace_by_prefix(xmlDocPtr doc, xmlNodePtr node, xmlNodePtr xml_parent, const char* prefix) {
xmlNsPtr ans = xmlSearchNs(doc, node, BAD_CAST prefix);
if (ans) return ans;
@@ -75,7 +86,6 @@ create_attributes(xmlDocPtr doc, xmlNodePtr node, GumboElement *elem, xmlNodePtr
char buf[50] = {0};
ParseData *pd = (ParseData*)doc->_private;
xmlNsPtr ns;
- xmlNodePtr root;
int added_lang = 0;
for (unsigned int i = 0; i < elem->attributes.length; ++i) {
@@ -85,12 +95,8 @@ create_attributes(xmlDocPtr doc, xmlNodePtr node, GumboElement *elem, xmlNodePtr
ns = NULL;
switch (attr->attr_namespace) {
case GUMBO_ATTR_NAMESPACE_XLINK:
- root = pd->root ? pd->root : node;
- if (UNLIKELY(!pd->xlink)) {
- pd->xlink = xmlNewNs(root, BAD_CAST "http://www.w3.org/1999/xlink", BAD_CAST "xlink");
- if(UNLIKELY(!pd->xlink)) return false;
- }
- ns = pd->xlink;
+ ns = ensure_xlink_ns(doc, pd, node);
+ if (UNLIKELY(!ns)) return false;
break;
case GUMBO_ATTR_NAMESPACE_XML:
ns = ensure_xml_ns(doc, pd, node);
@@ -105,11 +111,7 @@ create_attributes(xmlDocPtr doc, xmlNodePtr node, GumboElement *elem, xmlNodePtr
break;
case GUMBO_ATTR_NAMESPACE_XMLNS:
if (strncmp(aname, "xlink", 5) == 0) {
- root = pd->root ? pd->root : node;
- if (UNLIKELY(!pd->xlink)) {
- pd->xlink = xmlNewNs(root, BAD_CAST "http://www.w3.org/1999/xlink", BAD_CAST "xlink");
- if(UNLIKELY(!pd->xlink)) return false;
- }
+ if (!ensure_xlink_ns(doc, pd, node)) return false;
// We ignore the value of this attribute since we dont want
// the xlink namespace to be redefined
continue;
diff --git a/src/python-wrapper.c b/src/python-wrapper.c
index b2afff5..b17392b 100644
--- a/src/python-wrapper.c
+++ b/src/python-wrapper.c
@@ -15,7 +15,7 @@
#define MAJOR 0
#define MINOR 4
-#define PATCH 8
+#define PATCH 9
static char *NAME = "libxml2:xmlDoc";
static char *DESTRUCTOR = "destructor:xmlFreeDoc";
diff --git a/test/namespace.py b/test/namespace.py
index f907a92..06d8741 100644
--- a/test/namespace.py
+++ b/test/namespace.py
@@ -177,3 +177,12 @@ class NamespaceTests(TestCase):
a = p[0]
self.ae(a.attrib, {'{1}a': 'a', '{2}a': 'b', 'n': 'm'})
self.ae(a.tag, '{1}one')
+
+ def test_xlink(self):
+ src = '''<html xmlns:xlink="xl"><svg><image xlink:href="x"/>'''
+ root = parse(src, maybe_xhtml=True)
+ self.ae(
+ tostring(root),
+ '''<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="xl"><head/><body>\
+<svg xmlns="http://www.w3.org/2000/svg"><image xlink:href="x"/></svg></body></html>'''
+ )