diff --git a/ckanext/schemingdcat/profiles/base.py b/ckanext/schemingdcat/profiles/base.py index 2e1760f..1b785ec 100644 --- a/ckanext/schemingdcat/profiles/base.py +++ b/ckanext/schemingdcat/profiles/base.py @@ -1,6 +1,7 @@ import re import logging import json +from urllib.parse import quote from rdflib import term, URIRef, Literal @@ -536,12 +537,15 @@ def _add_valid_url_to_graph(self, graph, subject, predicate, url, fallback_url): url (str): The URL to validate and add. fallback_url (str): The fallback URL to use if the URL is not valid. """ - valid_url = URIRef(url) if is_url(url) else None - if valid_url: - graph.add((subject, predicate, valid_url)) - elif fallback_url: - graph.add((subject, predicate, URIRef(fallback_url))) - + if isinstance(url, str): + encoded_url = quote(url, safe=':/?&=') + valid_url = URIRef(encoded_url) if is_url(encoded_url) else None + if valid_url: + graph.add((subject, predicate, valid_url)) + elif fallback_url and isinstance(fallback_url, str): + encoded_fallback_url = quote(fallback_url, safe=':/?&=') + graph.add((subject, predicate, URIRef(encoded_fallback_url))) + def _is_direct_download_url(self, url): """ Check if the URL is a direct download link. diff --git a/ckanext/schemingdcat/profiles/eu_dcat_ap_base.py b/ckanext/schemingdcat/profiles/eu_dcat_ap_base.py index 77a4fcf..f274966 100644 --- a/ckanext/schemingdcat/profiles/eu_dcat_ap_base.py +++ b/ckanext/schemingdcat/profiles/eu_dcat_ap_base.py @@ -831,7 +831,8 @@ def _graph_from_dataset_base(self, dataset_dict, dataset_ref): # Use access_url/download_url if it exists and is a valid URL, otherwise use url self._add_valid_url_to_graph(g, distribution, DCAT.accessURL, access_url, url) - self._add_valid_url_to_graph(g, distribution, DCAT.downloadURL, download_url, url) + if download_url: + self._add_valid_url_to_graph(g, distribution, DCAT.downloadURL, download_url, url) # Dates items = [