summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Scott <dan@coffeecode.net>2016-01-16 14:13:02 -0500
committerDan Scott <dan@coffeecode.net>2016-01-16 14:13:02 -0500
commit8bbbc80abc9afade748a82d01f50a002b68501f5 (patch)
tree3928911df5c2ad7e4ac19bfb32ac9ab4418b4c1b
parent7eae68ba96cd834c62600c1bba7f26f859d6a620 (diff)
downloadrdflib-8bbbc80abc9afade748a82d01f50a002b68501f5.tar.gz
Prevent RDFa parser from failing on time elements with child nodes
The _get_literal() function in the RDFa parser referred to a self instance that does not exist. This led to a NameError exception if the HTML to be parsed included a TIME element with one or more child nodes, such as '<time><em>2016-01-01</em></time>'. Removing the reference to 'self' fixes the problem and fixes #576. Signed-off-by: Dan Scott <dan@coffeecode.net>
-rw-r--r--rdflib/plugins/parsers/pyRdfa/host/html5.py2
-rw-r--r--test/test_issue576.py26
2 files changed, 27 insertions, 1 deletions
diff --git a/rdflib/plugins/parsers/pyRdfa/host/html5.py b/rdflib/plugins/parsers/pyRdfa/host/html5.py
index b7420aad..1e839a2c 100644
--- a/rdflib/plugins/parsers/pyRdfa/host/html5.py
+++ b/rdflib/plugins/parsers/pyRdfa/host/html5.py
@@ -172,7 +172,7 @@ def html5_extra_attributes(node, state) :
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
elif node.nodeType == node.ELEMENT_NODE :
- rc = rc + self._get_literal(node)
+ rc = rc + _get_literal(node)
if state.options.space_preserve :
return rc
else :
diff --git a/test/test_issue576.py b/test/test_issue576.py
new file mode 100644
index 00000000..250138ab
--- /dev/null
+++ b/test/test_issue576.py
@@ -0,0 +1,26 @@
+import rdflib
+
+html = """<!DOCTYPE html>
+<html>
+ <head>
+ <title>Boom</title>
+ </head>
+<body vocab="http://schema.org/" typeof="Book" resource="http://example.com/">
+ <time property="dateCreated"><em>2016-01-01</em></time>
+</body>
+</html>
+"""
+
+
+def test_time_child_element():
+ """
+ Ensure TIME elements that contain child nodes parse cleanly
+ """
+ g = rdflib.Graph()
+ g.parse(data=html, format='rdfa')
+ date = g.value(
+ rdflib.URIRef("http://example.com/"),
+ rdflib.URIRef("http://schema.org/dateCreated")
+ )
+ assert len(g) == 3
+ assert date == rdflib.term.Literal("2016-01-01")