From fa963722a79c26c1642bbf81a2e153bd0c1a3fe8 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 8 Nov 2019 19:24:33 -0500 Subject: [PATCH] Fix seekForward and seekBackward not handling length=0 case correctly --- ext/fg/js/source.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index c3da9f46..5be521fa 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -108,6 +108,10 @@ class TextSourceRange { static seekForward(node, offset, length) { const state = {node, offset, remainder: length, content: ''}; + if (length <= 0) { + return state; + } + const TEXT_NODE = Node.TEXT_NODE; const ELEMENT_NODE = Node.ELEMENT_NODE; let resetOffset = false; @@ -166,6 +170,10 @@ class TextSourceRange { static seekBackward(node, offset, length) { const state = {node, offset, remainder: length, content: ''}; + if (length <= 0) { + return state; + } + const TEXT_NODE = Node.TEXT_NODE; const ELEMENT_NODE = Node.ELEMENT_NODE; let resetOffset = false;