From e2aa1bdb1d82ce0c5a4111aaa73d1ac4d30c71ad Mon Sep 17 00:00:00 2001 From: Javier Sagredo Date: Fri, 19 Jun 2026 00:26:09 +0200 Subject: [PATCH] Fix correctness, robustness, and tooling issues from code review MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Render: escape `<` to < in the embedded JSON so a `` in any string (e.g. a Haddock comment) can't close the data @ (e.g. inside a Haddock comment) would otherwise close the +-- script element early and corrupt — or inject into — the page. Inside a +-- JSON string @\\u003c@ decodes back to @<@; outside strings @<@ never +-- appears in JSON, so replacing the byte unconditionally is safe and keeps +-- the document valid. @<@ is ASCII (0x3c) and cannot occur inside a UTF-8 +-- multibyte sequence, so a byte-level rewrite is correct. +escapeForScript :: BL.ByteString -> BL.ByteString +escapeForScript = BL.concatMap esc + where + esc 0x3c = BL.pack [0x5c, 0x75, 0x30, 0x30, 0x33, 0x63] -- "<" + esc c = BL.singleton c + ------------------------------------------------------------------------------ -- Substitution helper -- 2.54.0