Repository navigation
fix(web): decode link-title entities without parsing the title as markup - #4
Closed
agentsfleet-dev[bot] wants to merge 1 commit into
Closed
agentsfleet-dev[bot] wants to merge 1 commit into
agentsfleet-dev[bot] wants to merge 1 commit into
Conversation
unescapeString passed the saved link title straight to DOMParser().parseFromString(input, "text/html"), so a title containing "<T>" was tokenised as an unknown start tag and dropped by documentElement.textContent: the title rendered as "TypeScript guide & examples" instead of "TypeScript <T> guide & examples". A link title is rendered as React text, never as markup, so escape "<" before parsing. Character references such as &, < and > are still decoded, while literal angle brackets are preserved. Adds the regression test of the failing run unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the failing step "Check link title decoding" of run 41199403249, attempt 1.
Evidence
event=pull_request, headtest/m224-link-title-decoding@95a173dfb71746d8e5ed01b420815668e34806f3, basedev@46303b321a43b6a8227c4dfdfcccce01ab37e55f.5196c8d640ba9a15382405cf7135fbebfa309748(job log, 12:03:50.3405660Z).124532028003"playwright-test-runner (@login)", 12:03:25Z → 12:05:43Z. Failing step Acceptance: watch-dog-22ec5177 #8 "Check link title decoding", 12:05:37Z → 12:05:39Z; steps 9–13 were skipped after it.yarn test run apps/web/lib/client/unescapeString.test.ts→Tests 1 failed | 2 passed (3):Root cause
unescapeString(apps/web/lib/client/unescapeString.ts) handed the saved link title straight toDOMParser().parseFromString(input, "text/html"), so the title was parsed as HTML markup, not as text. InTypeScript <T> guide & examplesthe parser tokenises<T>as an unknown start tag, anddocumentElement.textContent— which concatenates only text nodes — drops it, leaving the two surrounding spaces:"TypeScript " + "" + " guide & examples". That is exactly the received value in the log.A link title is rendered as React text —
{unescapeString(link.name)}inapps/web/components/LinkViews/LinkComponents/LinkCard.tsx— so the title must never be interpreted as markup. The two passing cases only passed because&,<and>are character references, which the parser decodes.The defect pre-exists on
dev; PR #3 added no production code, it only made CI assert it.Fix
Escape
<before parsing, so the title is always treated as text while character references are still decoded:Against the three assertions of the failing run:
Research & developmentResearch & development(unchanged)TypeScript <T> guideTypeScript <T> guide(unchanged)TypeScript <T> guide & examplesTypeScript <T> guide & examples(wasTypeScript guide & examples)Files changed
apps/web/lib/client/unescapeString.ts— the fix above.apps/web/lib/client/unescapeString.test.ts— the regression test of the failing run, added unchanged (blobff0b47366c02cbf165321919c5cb5b2980836c74, identical to the blob in the failing commit95a173d; the file does not exist ondev).No workflow file is modified. The step that runs this test (
Check link title decoding) lives on PR #3's branch; the regression can be executed locally withyarn test run apps/web/lib/client/unescapeString.test.ts.Validation
The fix was traced against the three assertions of the failing run; it has not been executed by a test runner in this environment, so the test result is still unverified here. CI on this pull request does not currently contain the
Check link title decodingstep.