Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow @base URI to have a trailing hash '#' #407

Merged
merged 5 commits into from
Jul 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rdflib/plugins/parsers/notation3.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def join(here, there):
%(u)s'http://example.org/#Andr\\xe9'
"""

assert(here.find("#") < 0), \
"Base may not contain hash: '%s'" % here # why must caller splitFrag?
# assert(here.find("#") < 0), \
# "Base may not contain hash: '%s'" % here # why must caller splitFrag?

slashl = there.find('/')
colonl = there.find(':')
Expand Down
56 changes: 56 additions & 0 deletions test/test_issue379.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import unittest

import rdflib

prefix_data = """
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <http://www.example.com#> .

<http://www.example.com#prefix> a rdf:class ."""

base_data = """
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@base <http://www.example.com#> .

<http://www.example.com#base> a rdf:class .
"""


class TestCase(unittest.TestCase):
def assertIsInstance(self, obj, cls, msg=None, *args, **kwargs):
"""Python < v2.7 compatibility. Assert 'obj' is instance of 'cls'"""
try:
f = super(TestCase, self).assertIsInstance
except AttributeError:
self.assertTrue(isinstance(obj, cls), *args, **kwargs)
else:
f(obj, cls, *args, **kwargs)


class TestBaseAllowsHash(TestCase):
"""
GitHub Issue 379: https://github.com/RDFLib/rdflib/issues/379
"""
def setUp(self):
self.g = rdflib.Graph()

def test_parse_successful_prefix_with_hash(self):
"""
Test parse of '@prefix' namespace directive to allow a trailing hash '#', as is
permitted for an IRIREF:
http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-prefixID
"""
self.g.parse(data=prefix_data, format='n3')
self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef)

def test_parse_successful_base_with_hash(self):
"""
Test parse of '@base' namespace directive to allow a trailing hash '#', as is
permitted for an '@prefix' since both allow an IRIREF:
http://www.w3.org/TR/2014/REC-turtle-20140225/#grammar-production-base
"""
self.g.parse(data=base_data, format='n3')
self.assertIsInstance(self.g.subjects().next(), rdflib.URIRef)

if __name__ == "__main__":
unittest.main()