Repository navigation
fix(hooks): render hook and memory cell text unescaped so React escapes it once - #35343
jeeshofone wants to merge 1 commit into
Conversation
…es it once The hooks table, the lessons table and the vector memory tables passed values through esc() and then rendered the result as JSX text. React escapes text children itself, so entities such as > showed literally. Render the raw values; React's own escaping keeps markup inert.
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) —
|
First Principles Review (Opus 5.5, fork) —
|
Design Review (Opus 5.5, fork) —
|
Code change approver recommendation: ApproveWhy: the decider estimates a 4% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. Removes a redundant esc() call in the JSX text cells of HooksPage, MemoryTab and VectorMemoryCard, so An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
|
This PR and #35348 both close #35264 and make the same fix. Each removes Please keep one of #35343 and #35348 and close the other, carrying over anything only this one has. |
Problem / Motivation
Goal: The Hooks table and the memory tables show hook and memory text exactly as written, with no stray
>or&.A hook whose command is
echo prompt >> /tmp/log.txtshows asecho prompt >> /tmp/log.txtin the Hooks table, and&shows as&. The Name and Matcher columns do the same. The memory pages have the same bug: a lesson ruleappend with >> & waitshows asappend with >> & wait, and so do semantic keys and values, episodic text, and audit keys and values.Why it matters
Anyone whose hook commands or memory text contain
<,>or&sees text that differs from what they saved, and the Command cell disagrees with its own tooltip. Shell commands with redirects and&&are common in hooks, so most non-trivial hooks are affected.Not a goal
esc()itself ormd(), which build HTML strings and still need escaping.esc()output as JSX text.What changed (motivation → approach → change)
Symptom: entities appear literally in table cells. Root cause: these cells passed the value through
esc()fromwebsite/src/api/helpers.ts, which HTML-escapes it, and then rendered the result as a JSX text child. React escapes text children itself, so the text was escaped twice. Change: render the raw value as JSX text inHooksPage.tsx(name, command, matcher),MemoryTab.tsx(lesson rule, unlabelled lesson source) andVectorMemoryCard.tsx(semantic key and value, episodic text, audit key and value), and drop the now-unusedescimports. React's own text escaping keeps any markup in the value inert; none of these sites usesdangerouslySetInnerHTMLor an HTML string builder.Backwards compatibility
Compatible: only the displayed text changes; no API, type or stored data changes.
Removes nothing: the diff only drops a redundant escaping call on display.
Tests
website/src/test/HooksPage.cellText.test.tsx(new): the name, command and matcher cells show>,&and<as written, the command tooltip matches the cell, and a<b>in the command is not parsed into an element.website/src/test/OverviewMemoryTabCov80.test.tsx: new case for a lesson rule and an unlabelled source carrying>,&and markup.website/src/test/VectorMemoryCardCoverage.test.tsx: new case covering the semantic, episodic and audit cells with the same payloads.All three fail with the page changes reverted and pass with them.
Proof: not provable -- frontend test
Manual verification
Built the SPA and rendered the Hooks page against stubbed API data with a hook named
log & notify, commandecho prompt >> /tmp/log.txt && notifyand matcher<any>, before and after the change. Ran typecheck, eslint, i18n check, jscpd, the file line cap, phantom-classes, restyle ratchet, ui-index freshness, Semgrep and the Hooks and memory test files (252 tests).Screenshots / video
Before (main): entities shown literally.
After: text shown as written.
Related Issues
Fixes #35264
Sibling sweep
Swept: git grep -n "esc(" -- website/src
Sibling: website/src/pages/overview/MemoryTab.tsx -- changed here
Sibling: website/src/pages/overview/VectorMemoryCard.tsx -- changed here
Sibling: website/src/api/helpers.ts -- not affected -- md() builds an HTML string that is sanitised before injection, so escaping is required there
Sibling: website/src/components/CommentOverlay.tsx -- not affected -- a local helper of the same name escapes prompt text, not HTML
Pattern harvest
Rule candidate: lint
Pattern: an HTML-escaping helper's result rendered as a JSX text child (
{esc(x)}), which React escapes againChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.