From 976f539c8cc0e98895896234fd85260de5d50f01 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 13 Aug 2013 15:34:39 -0700 Subject: [PATCH] Don't allow indexes larger than start node length --- builds/4chan-X.user.js | 8 ++++---- builds/crx/script.js | 8 ++++---- src/Linkification/Linkify.coffee | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index bd5e373f4..ec0d6b402 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -4438,7 +4438,7 @@ }); }, node: function() { - var data, el, end, endNode, i, index, items, lIndex, length, link, links, node, range, result, saved, snapshot, space, test, text, _i, _len, _ref; + var data, el, end, endNode, i, index, items, lIndex, len, length, link, links, node, range, result, saved, snapshot, space, test, text, _i, _len, _ref; if (this.isClone) { if (Conf['Embedding']) { @@ -4484,10 +4484,10 @@ } range = Linkify.makeRange(node, endNode, index, length); if (link = Linkify.regString.exec(text = range.toString())) { - if (lIndex = link.index) { - range.setStart(node, lIndex + index); - text = text.slice(0, lIndex); + if ((lIndex = link.index) && (len = lIndex + index) < node.data.length) { + range.setStart(node, len); } + text = text.slice(0, lIndex); links.push([range, text]); } break; diff --git a/builds/crx/script.js b/builds/crx/script.js index 166daccc8..7e63a60bb 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -4444,7 +4444,7 @@ }); }, node: function() { - var data, el, end, endNode, i, index, items, lIndex, length, link, links, node, range, result, saved, snapshot, space, test, text, _i, _len, _ref; + var data, el, end, endNode, i, index, items, lIndex, len, length, link, links, node, range, result, saved, snapshot, space, test, text, _i, _len, _ref; if (this.isClone) { if (Conf['Embedding']) { @@ -4490,10 +4490,10 @@ } range = Linkify.makeRange(node, endNode, index, length); if (link = Linkify.regString.exec(text = range.toString())) { - if (lIndex = link.index) { - range.setStart(node, lIndex + index); - text = text.slice(0, lIndex); + if ((lIndex = link.index) && (len = lIndex + index) < node.data.length) { + range.setStart(node, len); } + text = text.slice(0, lIndex); links.push([range, text]); } break; diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 7d1085aa8..ea237719e 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -76,9 +76,9 @@ Linkify = test.lastIndex = 0 if length is endNode.data.length range = Linkify.makeRange node, endNode, index, length if link = Linkify.regString.exec text = range.toString() - if lIndex = link.index - range.setStart node, lIndex + index - text = text[...lIndex] + if (lIndex = link.index) and (len = lIndex + index) < node.data.length + range.setStart node, len + text = text[...lIndex] links.push [range, text] break