oliver-zehentleitner / maity

clean-up: render.py language carry by one rule, and split render.py into languages, markdown and frame

Sign in to report

tsk-chrdtzp67af0 Review Maity Coder Claude 005

Follow-up of tsk-tnetc5fgr7pm (PR 2304), which left out audit item 5 and the render.py split of item 16 (audit tsk-hgnbapyw7hnh, area 11). Part 1, one rule for the language carry (audit item 5). render.py has the rule twice: _carry(href, lang) works on a URL (the frame model, also given to the dashboard by /site/chrome), and _carry_language applies it as a regex over the whole escaped body in _document. They detect an existing lang= differently: _carry_language looks for [?;&]lang= in the escaped HTML, _carry for (?:^|[;&])lang= in the URL. Letting _carry decide changes output. First pin these cases with tests, then the lead decides each one. (a) A query with a single quote right before lang=, such as /login?x= then a quote then lang=1. Escaped, the quote becomes a numeric HTML entity that ends in a semicolon, so today the HTML check sees a lang= and adds nothing; _carry would add lang. An operator can write such a link in Markdown. (b) If _carry also builds the link, /login? becomes /login?lang=en (today it is /login? followed by an escaped ampersand and lang=en). (c) /login with an empty fragment loses the fragment mark through urlsplit. (d) urlsplit strips tabs and newlines in the href. Behaviour changes only as the lead decides, and only with those tests in place. Optional later step: decorate links where they are built (_link, report_link) instead of parsing finished HTML again; carry_origin and _SWITCH are two more regex passes over the landing HTML. Part 2, split render.py (audit item 16). The module mixes Accept-Language negotiation used outside pages (registration_mail.py, routes/email_sign_in.py, routes/register_page.py), the Markdown renderer, the frame model behind GET /site/chrome (now with frame_inputs from PR 2304), and the page documents. Proposal: modules languages, markdown and frame, with render keeping the documents. No behaviour change, but every importer moves, so it is a PR of its own. Mind the import cycle landing_stats to public_projects to render; frame_inputs uses function-local imports for it (Keep the Why entry f166b81e-19a2-4f8c-be2e-9388781b1d9e in hub/context/public-pages.md). Order. After PR 2304 merges. The two parts can be separate PRs; part 2 first keeps part 1 small. Why. One language rule cannot drift into two answers, and the split keeps render.py reviewable.

Notes

  1. Maity Coder Claude 005 · Nov 30, 2026, 17:35 UTC

    Part 3: two nits from review A2961 of PR 2304 (tsk-tnetc5fgr7pm). The lead let PR 2304 merge as is and moved these here.

    1. One public cache value, for real. PR 2304 made public, max-age=60 one constant, landing.PUBLIC_CACHE. The middleware's public-cache gate still compares against two literal copies of its own (hub/src/maity_hub/middleware.py, the two public = b"public, max-age=60" lines, near 176 and 188 at that head). If PUBLIC_CACHE changed alone, public caching would silently fall back to no-store. That fails safe, but it is silent. Fix: let the middleware use landing.PUBLIC_CACHE.encode() (check for an import cycle), or else name the two copies in the comment above PUBLIC_CACHE. Either way, correct the changelog line from PR 2304 (changelog.d/coder-005-render-cleanup.md, or its entry in CHANGELOG.md once released) that calls it one constant.
    2. Register test, wrong password. In hub/tests/test_frame_headers.py, the register-page row for a wrong password checks only the headers. Also assert its status, which is 400, as the other rows do.