From a0539d878688a615b093a29ddd00528e08c33a14 Mon Sep 17 00:00:00 2001 From: zPlus Date: Sat, 25 Nov 2023 09:02:26 +0100 Subject: [PATCH] Add [ and ] to the list of %-encoded characters. --- scripts/rdf.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/rdf.py b/scripts/rdf.py index 8c774e2..a8d0795 100755 --- a/scripts/rdf.py +++ b/scripts/rdf.py @@ -25,11 +25,13 @@ def percent_encode(string): path. Since we use node URIs like , we need to percent-encode these otherwise the URLs are invalid. The reason for using a custom method instead of urllib.parse.quote() is that quote() - will percent-encode *any* non ASCII character such as non-latin characters. + will percent-encode *any* non-ASCII character. """ return string.replace(' ', '_') \ - .replace('#', '%23') + .replace('#', '%23') \ + .replace('[', '%5B') \ + .replace(']', '%5D') for absolute_file_path in pathlib.Path(DEBIMAN_SERVING_DIR).glob('**/*.roff'): if not absolute_file_path.is_file(): @@ -75,7 +77,7 @@ for absolute_file_path in pathlib.Path(DEBIMAN_SERVING_DIR).glob('**/*.roff'): # because I haven't got enough RAM for storing thousands of pages. g_page = Graph() - page_ref = URIRef('dokk:manpages:debian/' + percent_encode(f'{distro_number}/{distro_package}/{filename}')) + page_ref = URIRef(percent_encode(f'dokk:manpages:debian/{distro_number}/{distro_package}/{filename}')) g_page.add((page_ref, RDF.type, URIRef(MANPAGE.Page))) g_page.add((page_ref, URIRef(MANPAGE.filename), Literal(filename))) g_page.add((page_ref, URIRef(MANPAGE.name), Literal(name))) @@ -93,14 +95,14 @@ for absolute_file_path in pathlib.Path(DEBIMAN_SERVING_DIR).glob('**/*.roff'): # Create a graph node for this package # Link to the page node - package_ref = URIRef('dokk:manpages:debian/' + percent_encode(f'{distro_number}/{distro_package}')) + package_ref = URIRef(percent_encode(f'dokk:manpages:debian/{distro_number}/{distro_package}')) g.add((package_ref, RDF.type, URIRef(MANPAGE.Package))) g.add((package_ref, MANPAGE.name, Literal(distro_package))) g.add((package_ref, MANPAGE.page, page_ref)) # Create a graph node for this distro # Link to the package node - distro_ref = URIRef('dokk:manpages:debian/' + percent_encode(f'{distro_number}')) + distro_ref = URIRef(percent_encode(f'dokk:manpages:debian/{distro_number}')) g.add((distro_ref, RDF.type, URIRef(MANPAGE.Distribution))) g.add((distro_ref, MANPAGE.name, Literal('debian'))) g.add((distro_ref, MANPAGE.codename, Literal(distro_codename)))