From d01bad1c85894580c4119efe0f2a58e2241803ea Mon Sep 17 00:00:00 2001
From: "Rost S." <63606118+NeoZorK@users.noreply.github.com>
Date: Wed, 18 Nov 2026 15:19:47 +0200
Subject: [PATCH] Fix the CodeQL warnings: closing tag patterns and the XML
character set
Signed-off-by: Rost S. <63606118+NeoZorK@users.noreply.github.com>
---
docs/assets/protocolith/concept_d.svg | 1 +
docs/assets/protocolith/logo-mark-v2-dark.svg | 1 +
docs/assets/protocolith/logo-mark-v2.svg | 1 +
docs/assets/protocolith/logo-v2-dark.svg | 1 +
docs/assets/protocolith/logo-v2.svg | 1 +
scripts/protocolith_run_esa_factory.py | 4 ++--
scripts/protocolith_run_leqembi_campaign.py | 2 +-
scripts/protocolith_run_nasa_factory.py | 4 ++--
src/protocolith/core/issue.py | 10 ++++++++--
9 files changed, 18 insertions(+), 7 deletions(-)
create mode 100644 docs/assets/protocolith/concept_d.svg
create mode 100644 docs/assets/protocolith/logo-mark-v2-dark.svg
create mode 100644 docs/assets/protocolith/logo-mark-v2.svg
create mode 100644 docs/assets/protocolith/logo-v2-dark.svg
create mode 100644 docs/assets/protocolith/logo-v2.svg
diff --git a/docs/assets/protocolith/concept_d.svg b/docs/assets/protocolith/concept_d.svg
new file mode 100644
index 000000000..52efcf3ae
--- /dev/null
+++ b/docs/assets/protocolith/concept_d.svg
@@ -0,0 +1 @@
+
diff --git a/docs/assets/protocolith/logo-mark-v2-dark.svg b/docs/assets/protocolith/logo-mark-v2-dark.svg
new file mode 100644
index 000000000..45ad6ecb6
--- /dev/null
+++ b/docs/assets/protocolith/logo-mark-v2-dark.svg
@@ -0,0 +1 @@
+
diff --git a/docs/assets/protocolith/logo-mark-v2.svg b/docs/assets/protocolith/logo-mark-v2.svg
new file mode 100644
index 000000000..52efcf3ae
--- /dev/null
+++ b/docs/assets/protocolith/logo-mark-v2.svg
@@ -0,0 +1 @@
+
diff --git a/docs/assets/protocolith/logo-v2-dark.svg b/docs/assets/protocolith/logo-v2-dark.svg
new file mode 100644
index 000000000..b4c3d227e
--- /dev/null
+++ b/docs/assets/protocolith/logo-v2-dark.svg
@@ -0,0 +1 @@
+
diff --git a/docs/assets/protocolith/logo-v2.svg b/docs/assets/protocolith/logo-v2.svg
new file mode 100644
index 000000000..bb1062058
--- /dev/null
+++ b/docs/assets/protocolith/logo-v2.svg
@@ -0,0 +1 @@
+
diff --git a/scripts/protocolith_run_esa_factory.py b/scripts/protocolith_run_esa_factory.py
index 37991430d..0102e9829 100644
--- a/scripts/protocolith_run_esa_factory.py
+++ b/scripts/protocolith_run_esa_factory.py
@@ -72,8 +72,8 @@ def _write_json(path: Path, data: object) -> bytes:
def _normalize_html(payload: bytes) -> str:
text = payload.decode("utf-8", errors="replace")
- text = re.sub(r"", " ", text, flags=re.I | re.S)
- text = re.sub(r"", " ", text, flags=re.I | re.S)
+ text = re.sub(r"]*>", " ", text, flags=re.I | re.S)
+ text = re.sub(r"]*>", " ", text, flags=re.I | re.S)
text = re.sub(r"<[^>]+>", " ", text)
text = html.unescape(text)
for before, after in {
diff --git a/scripts/protocolith_run_leqembi_campaign.py b/scripts/protocolith_run_leqembi_campaign.py
index 88a60d4a8..2629742f7 100644
--- a/scripts/protocolith_run_leqembi_campaign.py
+++ b/scripts/protocolith_run_leqembi_campaign.py
@@ -47,7 +47,7 @@ def sha(data: bytes) -> str:
def normalized(data: bytes) -> str:
text = data.decode("utf-8", "replace")
- text = re.sub(r"|", " ", text, flags=re.I | re.S)
+ text = re.sub(r"]*>|]*>", " ", text, flags=re.I | re.S)
text = html.unescape(re.sub(r"<[^>]+>", " ", text))
return re.sub(r"\s+", " ", text).strip()
diff --git a/scripts/protocolith_run_nasa_factory.py b/scripts/protocolith_run_nasa_factory.py
index bb17e9edb..e99f8c1da 100644
--- a/scripts/protocolith_run_nasa_factory.py
+++ b/scripts/protocolith_run_nasa_factory.py
@@ -72,8 +72,8 @@ def _write_json(path: Path, data: object) -> bytes:
def _normalize_html(payload: bytes) -> str:
text = payload.decode("utf-8", errors="replace")
- text = re.sub(r"", " ", text, flags=re.I | re.S)
- text = re.sub(r"", " ", text, flags=re.I | re.S)
+ text = re.sub(r"]*>", " ", text, flags=re.I | re.S)
+ text = re.sub(r"]*>", " ", text, flags=re.I | re.S)
text = re.sub(r"<[^>]+>", " ", text)
text = html.unescape(text)
for before, after in {
diff --git a/src/protocolith/core/issue.py b/src/protocolith/core/issue.py
index 074059727..5a5045353 100644
--- a/src/protocolith/core/issue.py
+++ b/src/protocolith/core/issue.py
@@ -17,7 +17,13 @@
_MISSING_RE = re.compile(r"^missing (?:required |forecast |public claim )?field: (\w+)$")
_MUST_INCLUDE_RE = re.compile(r"must include (\w+)$")
-_XML_INVALID = re.compile("[\x00-\x08\x0b\x0c\x0e-\x1f\ufffe\uffff]") # not allowed in XML 1.0 documents
+# Characters that are not allowed in XML 1.0 documents (listed as code points, not as a regular expression range).
+_XML_INVALID = frozenset(map(chr, (*range(0x00, 0x09), 0x0B, 0x0C, *range(0x0E, 0x20), 0xFFFE, 0xFFFF)))
+
+
+def _xml_safe(text: str) -> str:
+ """Replace the characters XML 1.0 cannot carry with U+FFFD."""
+ return "".join("\ufffd" if ch in _XML_INVALID else ch for ch in text)
def _missing_names(violations: list[str]) -> list[str]:
@@ -94,5 +100,5 @@ def write_card_files(card: dict[str, Any], out_dir: Path) -> tuple[Path, Path]:
raise InputError("CARD_EXISTS", f"{json_path.name} already exists with different content; use another --out")
_atomic_write(json_path, payload)
# Card text is user data and may hold characters XML 1.0 forbids; the JSON card keeps them verbatim.
- _atomic_write(svg_path, _XML_INVALID.sub("\ufffd", render_svg(json_path)).encode("utf-8"))
+ _atomic_write(svg_path, _xml_safe(render_svg(json_path)).encode("utf-8"))
return json_path, svg_path