Changeset 00d54bc in Klonkt


Ignore:
Timestamp:
06/16/2026 03:38:33 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
5f43245
Parents:
baa2e59
Message:

Fix: htmx-partial 500 on non-ASCII characters in post title

The HX-Trigger-After-Settle header received the post title unfiltered via
JSON.stringify. HTTP header values are Latin-1; an em-dash, smart quote,
or emoji in the title (e.g. "Welkom — gebouwd met Klonkt") caused setHeader
to throw ERR_INVALID_CHAR -> partial 500 -> the card appeared "not clickable"
(full page worked fine, as it doesn't set the header).

Escape non-ASCII to \uXXXX: the header stays ASCII-safe and valid JSON that
htmx reads back unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/middleware/render.js

    rbaa2e59 r00d54bc  
    9595
    9696    if (isPartial) {
    97       // HTMX: just send the content. Set HX-Trigger for body class swap
    98       res.setHeader('HX-Trigger-After-Settle', JSON.stringify({
     97      // HTMX: just send the content. Set HX-Trigger for body class swap.
     98      // HTTP-header values are Latin-1 only — a title with an em-dash, smart
     99      // quote or emoji (e.g. "Welkom — gebouwd met Klonkt") would make
     100      // setHeader throw ERR_INVALID_CHAR and 500 the partial, so the card
     101      // looks "unclickable". Escape any non-ASCII to \uXXXX: the header stays
     102      // ASCII-safe and remains valid JSON that htmx parses back unchanged.
     103      const triggerJson = JSON.stringify({
    99104        pcmsNav: { bodyClass: locals.bodyClass },
    100105        pcmsPostSwap: data.post ? {
     
    103108          pageTitle: locals.pageTitle,
    104109        } : null,
    105       }));
     110      }).replace(/[€-￿]/g, (ch) => '\\u' + ch.charCodeAt(0).toString(16).padStart(4, '0'));
     111      res.setHeader('HX-Trigger-After-Settle', triggerJson);
    106112      return res.send(pageContent);
    107113    }
Note: See TracChangeset for help on using the changeset viewer.