fastmail/Squire

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

ganthern opened this issue · 1 comments

  • 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

neilj commented

Thanks for the report!