Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/pyff/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ def _setup(self):
if os.path.isdir(pth):
self.url = f"dir://{pth}"
elif os.path.isfile(pth) or os.path.isabs(self.url):
self.url = f"file://{pth}"
# Escape the path, as for files found in a directory: '#', '?' and '%' are URL syntax.
self.url = f"file://{urlescape(pth)}"

if self.url.startswith('file://') or self.url.startswith('dir://'):
self.never_expires = True
Expand Down
33 changes: 33 additions & 0 deletions src/pyff/test/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,39 @@ def test_no_fail_on_error_invalid_dir(self):
assert md.lookup('https://idp.example.com/saml2/idp/metadata.php')


class LoadFileNameTest(PipeLineTest):
"""
A metadata file loads whatever characters its name contains, also when it is listed directly rather than found
in a directory: cf. issue #291.
"""

NAMES = [
'plain.xml',
'a#b.xml',
'a?b.xml',
'a%20b.xml',
'https%3A%2F%2Fidp.example.com%2Fidp.xml',
'åäö.xml',
'Räksmörgås#1.xml',
]

def setUp(self):
super().setUp()
self.tmpdir = tempfile.mkdtemp()

def tearDown(self):
shutil.rmtree(self.tmpdir)

def test_file_name_with_url_special_characters(self):
for name in self.NAMES:
with self.subTest(name=name):
path = os.path.join(self.tmpdir, name)
shutil.copy(os.path.join(self.datadir, 'metadata', 'test01.xml'), path)
_res, md = self.exec_pipeline(f"- load:\n - {path}\n")
assert md.lookup('https://idp.example.com/saml2/idp/metadata.php'), f"{name} was not loaded"
os.unlink(path)


class SortTest(PipeLineTest):
EID1 = "https://idp.aco.net/idp/shibboleth"
EID2 = "https://idp.example.com/saml2/idp/metadata.php"
Expand Down
Loading