From 4fb52d3cf79fe5a5abfe9b7b7098b92ab2db4ed3 Mon Sep 17 00:00:00 2001 From: Martin Lehmann Date: Fri, 8 Nov 2024 10:45:27 +0100 Subject: [PATCH] fix: Parse 'hlink://' URIs as proper URIs --- capellambse/helpers.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/capellambse/helpers.py b/capellambse/helpers.py index 006485d30..df5eb55a4 100644 --- a/capellambse/helpers.py +++ b/capellambse/helpers.py @@ -20,6 +20,7 @@ import sys import time import typing as t +import urllib.parse import lxml.html import markupsafe @@ -546,16 +547,18 @@ def replace_hlinks( """ def cb(el: etree._Element) -> None: - if ( - el.tag != "a" - or "href" not in el.attrib - or not el.attrib["href"].startswith("hlink://") - ): + if el.tag != "a" or "href" not in el.attrib: return - target = el.attrib["href"][8:] try: - obj = model.by_uuid(target) + url = urllib.parse.urlparse(el.attrib["href"]) + except ValueError: + return + if url.scheme != "hlink": + return + + try: + obj = model.by_uuid(url.netloc) except KeyError: pass else: