From 7e2cdef1503c566c4ebd73485e3e98392dd03e4a Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 10 Nov 2026 15:37:35 -0700 Subject: [PATCH] fix: clear all tags from the editor; escape captions in feed HTML (v2.14.1) Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 ++ docs/design/INDEX.md | 6 +- .../v2.14.1/2026-11-10-tags-and-captions.md | 27 ++++++ docs/projectplan/BACKLOG.md | 14 +-- docs/projectplan/INDEX.md | 1 + docs/projectplan/v2.14.1/RELEASE.md | 15 ++++ starpunk/__init__.py | 4 +- starpunk/feeds/atom.py | 5 +- starpunk/feeds/json_feed.py | 5 +- starpunk/feeds/rss.py | 9 +- starpunk/routes/admin.py | 4 +- tests/test_tags_and_captions.py | 89 +++++++++++++++++++ 12 files changed, 163 insertions(+), 23 deletions(-) create mode 100644 docs/design/v2.14.1/2026-11-10-tags-and-captions.md create mode 100644 docs/projectplan/v2.14.1/RELEASE.md create mode 100644 tests/test_tags_and_captions.py diff --git a/CHANGELOG.md b/CHANGELOG.md index a557145..872829e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.14.1] - 2026-11-10 + +### Fixed + +- Clearing the Tags field in the note editor removes all of the note's tags. It used to leave them unchanged, so a note's last tags couldn't be removed from the editor +- Image captions are escaped in the HTML of RSS, Atom and JSON Feed items. A caption containing `"`, `<` or `&` broke the item's image markup (the Atom enclosure's title was already escaped) + ## [2.14.0] - 2026-11-10 Notifications (ADR-074). diff --git a/docs/design/INDEX.md b/docs/design/INDEX.md index 7049870..395295c 100644 --- a/docs/design/INDEX.md +++ b/docs/design/INDEX.md @@ -21,7 +21,7 @@ is in `../architecture/`; decisions are in `../decisions/` (ADRs). ## Contents -[v0.x](#v0x) · [v1.0.0](#v100) · [v1.1.1](#v111) · [v1.1.2](#v112) · [v1.2.0](#v120) · [v1.3.0](#v130) · [v1.3.1](#v131) · [v1.4.0](#v140) · [v1.4.1](#v141) · [v1.4.2](#v142) · [v1.5.0](#v150) · [v1.6.0](#v160) · [v2.0.0](#v200) · [v2.0.1](#v201) · [v2.0.2](#v202) · [v2.1.0](#v210) · [v2.2.0](#v220) · [v2.3.0](#v230) · [v2.3.1](#v231) · [v2.3.2](#v232) · [v2.3.3](#v233) · [v2.4.0](#v240) · [v2.5.0](#v250) · [v2.6.0](#v260) · [v2.6.1](#v261) · [v2.6.2](#v262) · [v2.6.3](#v263) · [v2.6.4](#v264) · [v2.6.5](#v265) · [v2.6.6](#v266) · [v2.6.7](#v267) · [v2.6.8](#v268) · [v2.6.9](#v269) · [v2.7.0](#v270) · [v2.7.1](#v271) · [v2.7.2](#v272) · [v2.8.0](#v280) · [v2.8.1](#v281) · [v2.9.0](#v290) · [v2.10.0](#v2100) · [v2.10.1](#v2101) · [v2.10.2](#v2102) · [v2.11.0](#v2110) · [v2.12.0](#v2120) · [v2.12.1](#v2121) · [v2.13.0](#v2130) · [v2.13.1](#v2131) · [v2.13.2](#v2132) · [v2.13.3](#v2133) · [v2.13.4](#v2134) · [v2.14.0](#v2140) · [hotfix](#hotfix) +[v0.x](#v0x) · [v1.0.0](#v100) · [v1.1.1](#v111) · [v1.1.2](#v112) · [v1.2.0](#v120) · [v1.3.0](#v130) · [v1.3.1](#v131) · [v1.4.0](#v140) · [v1.4.1](#v141) · [v1.4.2](#v142) · [v1.5.0](#v150) · [v1.6.0](#v160) · [v2.0.0](#v200) · [v2.0.1](#v201) · [v2.0.2](#v202) · [v2.1.0](#v210) · [v2.2.0](#v220) · [v2.3.0](#v230) · [v2.3.1](#v231) · [v2.3.2](#v232) · [v2.3.3](#v233) · [v2.4.0](#v240) · [v2.5.0](#v250) · [v2.6.0](#v260) · [v2.6.1](#v261) · [v2.6.2](#v262) · [v2.6.3](#v263) · [v2.6.4](#v264) · [v2.6.5](#v265) · [v2.6.6](#v266) · [v2.6.7](#v267) · [v2.6.8](#v268) · [v2.6.9](#v269) · [v2.7.0](#v270) · [v2.7.1](#v271) · [v2.7.2](#v272) · [v2.8.0](#v280) · [v2.8.1](#v281) · [v2.9.0](#v290) · [v2.10.0](#v2100) · [v2.10.1](#v2101) · [v2.10.2](#v2102) · [v2.11.0](#v2110) · [v2.12.0](#v2120) · [v2.12.1](#v2121) · [v2.13.0](#v2130) · [v2.13.1](#v2131) · [v2.13.2](#v2132) · [v2.13.3](#v2133) · [v2.13.4](#v2134) · [v2.14.0](#v2140) · [v2.14.1](#v2141) · [hotfix](#hotfix) ## v0.x @@ -452,6 +452,10 @@ OIDC admin login and built-in IndieAuth server. - [2026-11-10-notifications.md](v2.14.0/2026-11-10-notifications.md) — Notifications (implementation report) +## v2.14.1 + +- [2026-11-10-tags-and-captions.md](v2.14.1/2026-11-10-tags-and-captions.md) — Clearing tags in the editor; captions escaped in feeds + ## hotfix Not a release folder. diff --git a/docs/design/v2.14.1/2026-11-10-tags-and-captions.md b/docs/design/v2.14.1/2026-11-10-tags-and-captions.md new file mode 100644 index 0000000..001fbaf --- /dev/null +++ b/docs/design/v2.14.1/2026-11-10-tags-and-captions.md @@ -0,0 +1,27 @@ +# v2.14.1: Clearing tags in the editor; captions escaped in feeds + +Two bugs from the backlog (High), confirmed against the code at v2.14.0. + +## Clearing tags + +`routes/admin.py` (edit POST) passed `tags=tags if tags else None`, and +`notes.update_note` treats `None` as "unchanged", so an empty Tags field +kept the old tags although the form says "Leave blank to remove all tags". +It now passes the parsed list (possibly empty) whenever the form has a +`tags` field, and `None` only when it doesn't. + +## Captions in feed HTML + +The media `` built for item HTML put the caption into `alt="…"` +unescaped in four places: `feeds/rss.py` (two), `feeds/atom.py` and +`feeds/json_feed.py`. A caption with `"`, `<` or `&` broke the markup. The +caption and the media URL are now `html.escape(..., quote=True)`d. The +Atom enclosure's `title` attribute was already escaped with `_escape_xml` +and is unchanged (escaping it again would double it). + +## Verification + +`tests/test_tags_and_captions.py` (4 tests, all failing before the fix): +caption escaped once in RSS, Atom (and the enclosure title not doubled) and +JSON Feed; the editor leaves tags alone without the field and clears them +with an empty one. Feed, admin, tag, public-route and media tests pass. diff --git a/docs/projectplan/BACKLOG.md b/docs/projectplan/BACKLOG.md index 2e995fb..df643f8 100644 --- a/docs/projectplan/BACKLOG.md +++ b/docs/projectplan/BACKLOG.md @@ -23,17 +23,7 @@ at v2.14.0. Work that has shipped is listed per release in `vX.Y.Z/RELEASE.md` a ## High -Bugs (DOCUMENTATION.md: bugs are High). - -### Admin editor cannot clear all tags -- **Description**: When a note is saved with an empty tag field, the route passes `tags=None`. `update_note` treats that as "unchanged", so the last tags can't be removed from the editor. -- **Where**: `starpunk/routes/admin.py` (edit POST: `tags=tags if tags else None`), `starpunk/notes.py` (`update_note`) -- **Source**: Old backlog (v1.3.0 follow-up); still present - -### Media captions not escaped in RSS HTML -- **Description**: The RSS description embeds `{caption}` without escaping the caption. A caption containing `"` or `<` breaks the item's HTML. -- **Where**: `starpunk/feeds/rss.py` (two places, lines 131 and 258) -- **Source**: Old backlog (Architect Review 2.2.10); still present +None open. --- @@ -185,6 +175,8 @@ Bugs (DOCUMENTATION.md: bugs are High). These items were removed from the backlog because they have shipped: +- v2.14.1: the editor can clear all tags; image captions escaped in RSS, Atom and JSON Feed HTML + - v2.14.0: notifications of new responses and crosspost/backfeed problems through Apprise (ADR-074) - v2.13.0–v2.13.4: backfeed of likes, reposts, quotes and replies from GoToSocial, Bluesky and Threads (ADR-073); counts line with web actions; counts on lists of notes; local avatar copies - v2.12.1: Micropub `q=category` lists only tags in use diff --git a/docs/projectplan/INDEX.md b/docs/projectplan/INDEX.md index 9bb9195..9af7ff5 100644 --- a/docs/projectplan/INDEX.md +++ b/docs/projectplan/INDEX.md @@ -56,3 +56,4 @@ Future work and per-release plans. See `../DOCUMENTATION.md` (PROJECTPLAN). - **[v2.13.3](v2.13.3/RELEASE.md)** - Opted-out people counted without names (Released 2026-11-10) - **[v2.13.4](v2.13.4/RELEASE.md)** - Counts on lists of notes, reply cards link out (Released 2026-11-10) - **[v2.14.0](v2.14.0/RELEASE.md)** - Notifications through Apprise (Released 2026-11-10) +- **[v2.14.1](v2.14.1/RELEASE.md)** - Clearing tags in the editor; captions escaped in feeds (Released 2026-11-10) diff --git a/docs/projectplan/v2.14.1/RELEASE.md b/docs/projectplan/v2.14.1/RELEASE.md new file mode 100644 index 0000000..6ba6657 --- /dev/null +++ b/docs/projectplan/v2.14.1/RELEASE.md @@ -0,0 +1,15 @@ +# v2.14.1 + +- **Date**: 2026-11-10 +- **Status**: Released +- **Focus**: The two High backlog bugs + +## Fixed + +- The editor can clear all of a note's tags +- Image captions escaped in RSS, Atom and JSON Feed item HTML + +## Related + +- [CHANGELOG](../../../CHANGELOG.md) +- [Design note](../../design/v2.14.1/2026-11-10-tags-and-captions.md) diff --git a/starpunk/__init__.py b/starpunk/__init__.py index dc8a4cb..9aac3cc 100644 --- a/starpunk/__init__.py +++ b/starpunk/__init__.py @@ -465,5 +465,5 @@ def create_app(config=None): # Package version (Semantic Versioning 2.0.0) # See docs/standards/versioning-strategy.md for details -__version__ = "2.14.0" -__version_info__ = (2, 14, 0) +__version__ = "2.14.1" +__version_info__ = (2, 14, 1) diff --git a/starpunk/feeds/atom.py b/starpunk/feeds/atom.py index 8d1df3e..d253274 100644 --- a/starpunk/feeds/atom.py +++ b/starpunk/feeds/atom.py @@ -16,6 +16,7 @@ Standards: """ # Standard library imports +from html import escape from datetime import datetime, timezone from typing import Optional import xml.etree.ElementTree as ET @@ -199,8 +200,8 @@ def generate_atom_streaming( html_content += '
' for item in note.media: media_url = f"{site_url}/media/{item['path']}" - caption = item.get('caption', '') - html_content += f'{caption}' + caption = escape(item.get('caption') or '', quote=True) # v2.14.1 + html_content += f'{caption}' html_content += '
' # Add text content below media diff --git a/starpunk/feeds/json_feed.py b/starpunk/feeds/json_feed.py index 44c2ab9..bbcd161 100644 --- a/starpunk/feeds/json_feed.py +++ b/starpunk/feeds/json_feed.py @@ -16,6 +16,7 @@ Standards: """ # Standard library imports +from html import escape from datetime import datetime, timezone from typing import Optional, Dict, Any import json @@ -247,8 +248,8 @@ def _build_item_object(site_url: str, note: Note) -> Dict[str, Any]: content_html += '
' for media_item in note.media: media_url = f"{site_url}/media/{media_item['path']}" - caption = media_item.get('caption', '') - content_html += f'{caption}' + caption = escape(media_item.get('caption') or '', quote=True) # v2.14.1 + content_html += f'{caption}' content_html += '
' # Add text content below media diff --git a/starpunk/feeds/rss.py b/starpunk/feeds/rss.py index 80afcb1..3f383d5 100644 --- a/starpunk/feeds/rss.py +++ b/starpunk/feeds/rss.py @@ -20,6 +20,7 @@ Standards: """ # Standard library imports +from html import escape from datetime import datetime, timezone from typing import Optional @@ -127,8 +128,8 @@ def generate_rss( html_content += '
' for item in note.media: media_url = f"{site_url}/media/{item['path']}" - caption = item.get('caption', '') - html_content += f'{caption}' + caption = escape(item.get('caption') or '', quote=True) # v2.14.1 + html_content += f'{caption}' html_content += '
' # Add text content below media @@ -254,8 +255,8 @@ def generate_rss_streaming( html_content += '
' for item in note.media: media_url = f"{site_url}/media/{item['path']}" - caption = item.get('caption', '') - html_content += f'{caption}' + caption = escape(item.get('caption') or '', quote=True) # v2.14.1 + html_content += f'{caption}' html_content += '
' # Add text content below media diff --git a/starpunk/routes/admin.py b/starpunk/routes/admin.py index 1f48f72..e58af2e 100644 --- a/starpunk/routes/admin.py +++ b/starpunk/routes/admin.py @@ -309,7 +309,9 @@ def update_note_submit(note_id: int): id=note_id, content=content, published=published, - tags=tags if tags else None + # An empty Tags field removes all tags (v2.14.1); a form without + # the field leaves them alone + tags=tags if "tags" in request.form else None ) if "syndication_form" in request.form: from starpunk.syndication import select_targets diff --git a/tests/test_tags_and_captions.py b/tests/test_tags_and_captions.py new file mode 100644 index 0000000..002f387 --- /dev/null +++ b/tests/test_tags_and_captions.py @@ -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" bold & more' +ESCAPED = 'alt="Say "hi" <b>bold</b> & 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 "bold" 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 "bold" 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 "bold" 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) == []