fix: prevent signifier double-wrap and selector overlap (#3) - #7
Open
SmileyChris wants to merge 1 commit into
Open
SmileyChris wants to merge 1 commit into
SmileyChris wants to merge 1 commit into
Conversation
`element.findAll('ul > li')` and `element.findAll('.task-list-item')`
both match the same `<li>` for tasks, so the concatenated list
iterated task items twice and wrapped their signifiers in nested
`<span class="bujo-bullet-signifier">` elements. Query `ul > li`
once and derive the checkbox subset via `.filter`.
`bullet.innerHTML.replace(signifierText, ...)` also replaced the
first occurrence anywhere in the HTML, not only at the start of
the item's user-visible text, so lines like "is this ? okay" got
their `?` wrapped. Replace with a text-node DOM split using
`createTreeWalker` + `createTextNode` + `insertBefore`, scoped to
the first meaningful text node of each list item.
`textContent` assignment on the new span makes HTML injection
impossible, so the `isomorphic-dompurify` runtime dependency is
dropped.
Fixes frankolson#3. Supersedes frankolson#4.
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.
Summary
Fixes two bugs in the reading-mode post-processor reported in #3:
element.findAll('ul > li')andelement.findAll('.task-list-item')both match the same<li>for tasks, so the concatenated list iterated task items twice and wrapped their signifiers in nested<span class=\"bujo-bullet-signifier\"><span class=\"bujo-bullet-signifier\">?</span></span>elements. Queryul > lionce and derive the checkbox subset via.filter.bullet.innerHTML.replace(signifierText, ...)replaced the first occurrence anywhere in the HTML, not only at the start of the item's visible text. A line like "is this ? okay" had its?wrapped as if it were a leading signifier. Replace with a text-node DOM split usingcreateTreeWalker+createTextNode+insertBefore, scoped to the first meaningful text node of each list item.textContentassignment on the new span makes HTML injection impossible, so theisomorphic-dompurifyruntime dependency is dropped.Supersedes #4 — thanks @davidstosik for the original diagnosis of the selector overlap. This PR takes a slightly wider approach (also fixes the mid-text
innerHTML.replacebug and drops the sanitiser dep).Single-file change in
src/index.ts(+package.json/package-lock.jsonfor the dropped dep).Test plan
npm run buildsucceeds.!,?):- ! priority taskrenders with a single red!in reading mode.- [ ] ? follow uprenders with a single red?, no nested span.- is this ? okayshows no red?(regression case).- [x],- [-],- [>],- [<],- [o]) still render with their icons.