diff --git a/bin/__pycache__/inject-hashed-filenames.cpython-313.pyc b/bin/__pycache__/inject-hashed-filenames.cpython-313.pyc new file mode 100644 index 0000000..4a92e14 Binary files /dev/null and b/bin/__pycache__/inject-hashed-filenames.cpython-313.pyc differ diff --git a/bin/inject-hashed-filenames.py b/bin/inject-hashed-filenames.py index 0afdddc..2cb2d21 100755 --- a/bin/inject-hashed-filenames.py +++ b/bin/inject-hashed-filenames.py @@ -26,9 +26,29 @@ containing the config file's parent chain → `$PWD`). """ import json import os +import re import sys +def _build_pattern(old_src: str) -> "re.Pattern[str]": + # Match `src` on ' + out, n = ihf.rewrite(html, "/static/dist/app.js", "/static/dist/app.abc123.js") + assert n == 1 + assert out == '' + + +def test_rewrites_script_src_single_quoted(): + html = "" + out, n = ihf.rewrite(html, "/static/dist/app.js", "/static/dist/app.abc123.js") + assert n == 1 + assert "/static/dist/app.abc123.js" in out + + +def test_rewrites_link_href(): + html = '' + out, n = ihf.rewrite(html, "/static/dist/app.css", "/static/dist/app.abc123.css") + assert n == 1 + assert '/static/dist/app.abc123.css' in out + + +def test_does_not_rewrite_inside_html_comment(): + html = '' + out, n = ihf.rewrite(html, "/static/dist/app.js", "/static/dist/app.abc123.js") + assert n == 0 + assert "/static/dist/app.js" in out + assert "/static/dist/app.abc123.js" not in out + + +def test_does_not_rewrite_inside_json_literal(): + html = '
{ "src": "/static/dist/app.js" }'
+ out, n = ihf.rewrite(html, "/static/dist/app.js", "/static/dist/app.abc123.js")
+ assert n == 0
+ assert out == html
+
+
+def test_does_not_rewrite_unrelated_attribute():
+ html = '