Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linkifyText throws a DOMException if a link is inserted inside a text node #430

Closed
ganthern opened this issue Apr 19, 2023 · 1 comment
Closed

Comments

@ganthern
Copy link

ganthern commented Apr 19, 2023

  • open Demo.html
  • open DevTools
  • type "ww" into the text editor
  • press the left arrow key once
  • type a space
  • type "www.google.com"
  • type another space
  • see the error pop up in the console:
Uncaught DOMException: Index or size is negative or greater than the allowed amount squire-raw.js:1659
    linkifyText http://localhost:63342/Squire/dist/squire-raw.js:1659
    Space http://localhost:63342/Squire/dist/squire-raw.js:1845
    (Async: setTimeout handler)
    Space http://localhost:63342/Squire/dist/squire-raw.js:1844
    _onKey http://localhost:63342/Squire/dist/squire-raw.js:1906
    fireEvent http://localhost:63342/Squire/dist/squire-raw.js:2331
    handleEvent http://localhost:63342/Squire/dist/squire-raw.js:2303
    (Async: EventListener.handleEvent)
    addEventListener http://localhost:63342/Squire/dist/squire-raw.js:2350
    Squire http://localhost:63342/Squire/dist/squire-raw.js:2130
    <anonymous> http://localhost:63342/Squire/Demo.html?_ijt=v2lth7efi9vp5nvk8pc0gsmb1&_ij_reload=RELOAD_ON_SAVE:121

the reason are the following lines:

const startOffset = selection.startOffset;
textNode.data = data.slice(endIndex);
if (selection.startContainer === textNode) {
const newOffset = startOffset - endIndex;
selection.setStart(textNode, newOffset);
selection.setEnd(textNode, newOffset);
}

I'm not sure what the exact bug is here.

tutao/tutanota#5339

ganthern added a commit to ganthern/Squire that referenced this issue Apr 19, 2023
in cases where a link is added in the middle of a text node,
linkifyText will attempt to reset the selection to after
the linkified section and the inserted space that triggered
that linkification.

in some cases, this caused a DOMException with "Index or
size is negative or greater than the allowed amount"

setting the offset to 1 if the selection starts in
the same text node will put the cursor behind
the space that caused the linkification

fix fastmail#430
ganthern added a commit to ganthern/Squire that referenced this issue Apr 19, 2023
in cases where a link is added in the middle of a text node,
linkifyText will attempt to reset the selection to after
the linkified section and the inserted space that triggered
that linkification.

in some cases, this caused a DOMException with "Index or
size is negative or greater than the allowed amount"

setting the offset to 1 if the selection starts in
the same text node will put the cursor behind
the space that caused the linkification

fix fastmail#430
@neilj neilj closed this as completed in cbde453 Apr 20, 2023
@neilj
Copy link
Member

neilj commented Apr 20, 2023

Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants