fix: clear all tags from the editor; escape captions in feed HTML (v2.14.1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-10 15:37:35 -07:00
1 parent 058b1959f9
commit 7e2cdef150
12 files changed
+163 -23

No files matched your search

+89
View File
@@ -0,0 +1,89 @@
"""
v2.14.1 fixes: clearing all tags in the editor, and media captions escaped
in the HTML of RSS, Atom and JSON Feed items.
"""
import io
import json
from xml.etree import ElementTree as ET
import pytest
from PIL import Image
from starpunk import create_app
from starpunk.media import attach_media_to_note, save_media
from starpunk.notes import create_note
from starpunk.tags import get_note_tags
CAPTION = 'Say "hi" <b>bold</b> & more'
ESCAPED = 'alt="Say &quot;hi&quot; &lt;b&gt;bold&lt;/b&gt; &amp; more"'
@pytest.fixture
def app(tmp_path):
data = tmp_path / "data"
app = create_app({
"TESTING": True, "DATABASE_PATH": data / "starpunk.db", "DATA_PATH": data,
"NOTES_PATH": data / "notes", "SESSION_SECRET": "x", "ADMIN_ME": "https://example.com",
"SITE_URL": "https://blog.example.com", "SITE_NAME": "Test", "CSRF_ENABLED": False,
})
yield app
def png():
buf = io.BytesIO()
Image.new("RGB", (800, 600), "red").save(buf, "PNG")
return buf.getvalue()
@pytest.fixture
def captioned(app):
with app.app_context():
note = create_note(content="A photo", published=True)
media = save_media(png(), "photo.png")
attach_media_to_note(note.id, [media["id"]], [CAPTION])
return note
def test_rss_caption_escaped(app, captioned):
body = app.test_client().get("/feed.rss").get_data(as_text=True)
description = ET.fromstring(body).find("./channel/item/description").text
assert ESCAPED in description
assert "<b>bold</b>" not in description
def test_atom_caption_escaped_once(app, captioned):
body = app.test_client().get("/feed.atom").get_data(as_text=True)
ns = {"a": "http://www.w3.org/2005/Atom"}
entry = ET.fromstring(body).find("a:entry", ns)
content = entry.find("a:content", ns).text
assert ESCAPED in content and "<b>bold</b>" not in content
# The enclosure's title attribute was already escaped; not twice
enclosure = next(l for l in entry.findall("a:link", ns) if l.get("rel") == "enclosure")
assert enclosure.get("title") == CAPTION
def test_json_feed_caption_escaped(app, captioned):
item = json.loads(app.test_client().get("/feed.json").get_data(as_text=True))["items"][0]
assert ESCAPED in item["content_html"] and "<b>bold</b>" not in item["content_html"]
def test_editor_can_clear_all_tags(app):
from starpunk.auth import create_session
with app.app_context():
note = create_note(content="Tagged", published=True, tags=["one", "two"])
with app.test_request_context():
token = create_session("https://example.com")
client = app.test_client()
client.set_cookie("starpunk_session", token)
# A form without the Tags field leaves the tags alone
client.post(f"/admin/edit/{note.id}", data={"content": "Tagged", "published": "on"})
with app.app_context():
assert {t["name"] for t in get_note_tags(note.id)} == {"one", "two"}
# An empty Tags field removes them all
client.post(f"/admin/edit/{note.id}", data={"content": "Tagged", "published": "on", "tags": ""})
with app.app_context():
assert get_note_tags(note.id) == []