Fix broken reference links and web UI bugs

- Fix RFC URLs with leading zeros (rfc0020 -> rfc20) via int filter
- Draft refs: internal link for drafts in our DB, Datatracker for external
- BCP refs: link to rfc-editor.org/info/bcpN
- Add DB connection teardown (@app.teardown_appcontext)
- Fix JS syntax error in gap_demo.html (HTML-escaped string in script tag)
- Add URL encoding to all query params in drafts.html and draft_detail.html
- Fix variable shadowing of Flask's g import in gaps_demo()
- Add None safety for ideas search data attribute

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 07:59:45 +01:00
parent 6e3a387778
commit 75c4da72e0
6 changed files with 127 additions and 34 deletions

View File

@@ -57,6 +57,13 @@ def db():
return g.db
@app.teardown_appcontext
def close_db(exception=None):
database = g.pop("db", None)
if database is not None:
database.close()
# --- Routes ---
@@ -110,10 +117,20 @@ def drafts():
@app.route("/drafts/<path:name>")
def draft_detail(name: str):
detail = get_draft_detail(db(), name)
database = db()
detail = get_draft_detail(database, name)
if not detail:
abort(404)
return render_template("draft_detail.html", draft=detail)
# Build set of draft ref IDs that exist in our DB for internal linking
ref_draft_ids = [r["id"] for r in detail.get("refs", []) if r["type"] == "draft"]
known_drafts = set()
if ref_draft_ids:
placeholders = ",".join("?" * len(ref_draft_ids))
rows = database.conn.execute(
f"SELECT name FROM drafts WHERE name IN ({placeholders})", ref_draft_ids
).fetchall()
known_drafts = {r["name"] for r in rows}
return render_template("draft_detail.html", draft=detail, known_drafts=known_drafts)
@app.route("/ideas")
@@ -139,9 +156,9 @@ def gaps_demo():
draft_info = None
if selected:
draft_text = read_generated_draft(selected)
for g in generated:
if g["filename"] == selected:
draft_info = g
for gd in generated:
if gd["filename"] == selected:
draft_info = gd
break
elif generated:
draft_info = generated[0]