summaryrefslogtreecommitdiff
path: root/rdflib/namespace
diff options
context:
space:
mode:
authorTom Gillespie <tgbugs@gmail.com>2022-12-14 16:21:35 -0500
committerGitHub <noreply@github.com>2022-12-14 22:21:35 +0100
commitdb5c05aefc9620c032ef69a8e8eef4f8a19bb68c (patch)
treed20b4ea0bbd274da9a6b973b41cca4202cef1161 /rdflib/namespace
parentdef1c1fd355794e376bd8988c410b75598943990 (diff)
downloadrdflib-db5c05aefc9620c032ef69a8e8eef4f8a19bb68c.tar.gz
fix: compute_qname handle case where name could be unbound (#2169)
* compute_qname handle case where name could be unbound In NamespaceManager.compute_qname it is possible for the variable name to be unbound when a namespace is used as a predicate e.g. ns2: and the namespace itself cannot be split any further. Fixing this usually just kicks the can down the road because the only reason to hit this condition is that you are trying to serialize a predicate that has no valid NCName form into an xml format that requires one, making it impossible to complete the conversion. That said, this fix should make it easier to understand what is going on by unmasking the real issue. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * test_roundtrip.py and n3roundtrip suite add unbound name test The new test graph will produce the UnboundLocalError with the old code that is missing the name = '' assignment. The new code correctly produces the xfail ValueError when trying to convert to xml. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
Diffstat (limited to 'rdflib/namespace')
-rw-r--r--rdflib/namespace/__init__.py1
1 files changed, 1 insertions, 0 deletions
diff --git a/rdflib/namespace/__init__.py b/rdflib/namespace/__init__.py
index 98c8d3a6..585ecf30 100644
--- a/rdflib/namespace/__init__.py
+++ b/rdflib/namespace/__init__.py
@@ -504,6 +504,7 @@ class NamespaceManager(object):
except ValueError as e:
namespace = URIRef(uri)
prefix = self.store.prefix(namespace)
+ name = "" # empty prefix case, safe since not prefix is error
if not prefix:
raise e
if namespace not in self.__strie: