static_site_tests: disallow double quotes in filenames
- ID
132d3bc- date
2026-11-28 09:43:26+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
76bad89- message
static_site_tests: disallow double quotes in filenames- changed files
10 files, 37 additions, 35 deletions
Changed files
CHANGELOG.md (10231 → 10372)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2c4466d..5ae6baa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# CHANGELOG
+## v65 - 2026-11-28
+
+Move `is_url_safe` into `static_site_tests`, as it's only used there.
+Disallow using double quotes (`"`) in filenames.
+
## v64 - 2026-11-21
Add caching for `media.get_video_codec`, keyed by file path/mtime/size, to speed up static site tests that check video codecs.
javascript/chives-image.js (6918 → 6918)
diff --git a/javascript/chives-image.js b/javascript/chives-image.js
index 192dbbc..d3cbd57 100644
--- a/javascript/chives-image.js
+++ b/javascript/chives-image.js
@@ -1,5 +1,5 @@
// javascript/chives-image.js
-// chives version: 64
+// chives version: 65
// ChivesImage provides a <chives-image> component that renders
// an ImageEntity on a web page.
javascript/chives-pagination.js (4929 → 4929)
diff --git a/javascript/chives-pagination.js b/javascript/chives-pagination.js
index a283779..94e9dd1 100644
--- a/javascript/chives-pagination.js
+++ b/javascript/chives-pagination.js
@@ -1,5 +1,5 @@
// javascript/chives-pagination.js
-// chives version: 64
+// chives version: 65
// ChivesPagination manages the pagination of a collection of items.
//
javascript/chives-sorting.js (5034 → 5034)
diff --git a/javascript/chives-sorting.js b/javascript/chives-sorting.js
index 5a1bc0d..e40a4c2 100644
--- a/javascript/chives-sorting.js
+++ b/javascript/chives-sorting.js
@@ -1,5 +1,5 @@
// javascript/chives-sorting.js
-// chives version: 64
+// chives version: 65
// ChivesSorting manages the sorting of a collection of items.
//
javascript/chives-video.js (5521 → 5521)
diff --git a/javascript/chives-video.js b/javascript/chives-video.js
index b6a9abb..04875ec 100644
--- a/javascript/chives-video.js
+++ b/javascript/chives-video.js
@@ -1,5 +1,5 @@
// javascript/chives-video.js
-// chives version: 64
+// chives version: 65
// ChivesVideo provides a <chives-video> component that renders
// a VideoEntity on a web page.
python/chives/__init__.py (391 → 391)
diff --git a/python/chives/__init__.py b/python/chives/__init__.py
index 6c729c3..ddcc92e 100644
--- a/python/chives/__init__.py
+++ b/python/chives/__init__.py
@@ -11,4 +11,4 @@ I share across multiple sites.
"""
-__version__ = "64"
+__version__ = "65"
python/chives/static_site_tests.py (8752 → 8925)
diff --git a/python/chives/static_site_tests.py b/python/chives/static_site_tests.py
index 2aa4169..2de2e4f 100644
--- a/python/chives/static_site_tests.py
+++ b/python/chives/static_site_tests.py
@@ -18,12 +18,19 @@ import pytest
from chives import __version__, javascript
from chives.dates import date_matches_any_format, find_all_dates
from chives.media import get_video_codec
-from chives.urls import is_url_safe
T = TypeVar("T")
+def is_url_safe(path: str | Path) -> bool:
+ """
+ Return True if a path is safe to use in a URL, False otherwise.
+ """
+ p = str(path)
+ return not ("?" in p or "#" in p or "%" in p or '"' in p)
+
+
class StaticSiteTestSuite[M](ABC):
"""
Define a base set of tests to run against any of my static sites.
python/chives/urls.py (4610 → 4369)
diff --git a/python/chives/urls.py b/python/chives/urls.py
index 0a495f0..609a6e3 100644
--- a/python/chives/urls.py
+++ b/python/chives/urls.py
@@ -2,7 +2,6 @@
from contextlib import closing
import json
-from pathlib import Path
import re
import ssl
from ssl import SSLCertVerificationError
@@ -15,7 +14,6 @@ import urllib.request
__all__ = [
"clean_youtube_url",
"is_mastodon_host",
- "is_url_safe",
"parse_mastodon_post_url",
"parse_tumblr_post_url",
]
@@ -164,11 +162,3 @@ def parse_tumblr_post_url(url: str) -> tuple[str, str]:
else:
raise ValueError("Cannot parse Tumblr URL!")
-
-
-def is_url_safe(path: str | Path) -> bool:
- """
- Return True if a path is safe to use in a URL, False otherwise.
- """
- p = str(path)
- return not ("?" in p or "#" in p or "%" in p)
tests/python/test_static_site_tests.py (12230 → 12802)
diff --git a/tests/python/test_static_site_tests.py b/tests/python/test_static_site_tests.py
index 42a6f8b..258a8d6 100644
--- a/tests/python/test_static_site_tests.py
+++ b/tests/python/test_static_site_tests.py
@@ -11,6 +11,7 @@ import pytest
from pytest import Pytester
from chives import dates
+from chives.static_site_tests import is_url_safe
M = TypeVar("M")
@@ -388,3 +389,21 @@ class TestChivesJSisUpToDate:
keyword = "test_chives_js_is_up_to_date"
pytester.runpytest("-k", keyword).assert_outcomes(failed=1)
+
+
+class TestIsUrlSafe:
+ """
+ Tests for `is_url_safe`.
+ """
+
+ @pytest.mark.parametrize("path", ["example.txt", Path("a/b/cat.jpg")])
+ def test_safe(self, path: str | Path) -> None:
+ """Paths which are URL safe."""
+ assert is_url_safe(path)
+
+ @pytest.mark.parametrize(
+ "path", ["is it?", Path("cat%c.jpg"), "a#b", '"don’t use double quotes"']
+ )
+ def test_unsafe(self, path: str | Path) -> None:
+ """Paths which are not URL safe."""
+ assert not is_url_safe(path)
tests/python/test_urls.py (5940 → 5419)
diff --git a/tests/python/test_urls.py b/tests/python/test_urls.py
index 258fb5c..a183a5c 100644
--- a/tests/python/test_urls.py
+++ b/tests/python/test_urls.py
@@ -1,14 +1,11 @@
"""Tests for `chives.urls`."""
-from pathlib import Path
-
import pytest
from vcr.cassette import Cassette
from chives.urls import (
clean_youtube_url,
is_mastodon_host,
- is_url_safe,
parse_mastodon_post_url,
parse_tumblr_post_url,
)
@@ -188,19 +185,3 @@ class TestIsMastodonHost:
Other websites are not Mastodon servers.
"""
assert not is_mastodon_host(host)
-
-
-class TestIsUrlSafe:
- """
- Tests for `is_url_safe`.
- """
-
- @pytest.mark.parametrize("path", ["example.txt", Path("a/b/cat.jpg")])
- def test_safe(self, path: str | Path) -> None:
- """Paths which are URL safe."""
- assert is_url_safe(path)
-
- @pytest.mark.parametrize("path", ["is it?", Path("cat%c.jpg"), "a#b"])
- def test_unsafe(self, path: str | Path) -> None:
- """Paths which are not URL safe."""
- assert not is_url_safe(path)