From: Aleksander Ɓukasz Date: Tue, 11 Feb 2014 16:09:36 +0000 (+0100) Subject: smartxml: fix in DocumentNode.getParentSiblings X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/a849d4765ded55173cc10ba3e55a483d281b9174?ds=sidebyside;hp=-c smartxml: fix in DocumentNode.getParentSiblings --- a849d4765ded55173cc10ba3e55a483d281b9174 diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 102a506..7eab11b 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -373,13 +373,17 @@ $.extend(Document.prototype, Backbone.Events, { return noSiblingParents; } - var i; - for(i = 0; i < Math.min(parents1.length, parents2.length); i++) { + var stop = Math.min(parents1.length, parents2.length), + i; + for(i = 0; i < stop; i++) { if(parents1[i].sameNode(parents2[i])) { continue; } break; } + if(i === stop) { + i--; + } return {node1: parents1[i], node2: parents2[i]}; }, diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index 1e778ce..3410407 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -1112,6 +1112,16 @@ describe('smartxml', function() { expect(siblingParents.node1.sameNode(aliceText)).to.equal(true, 'aliceText'); expect(siblingParents.node2.sameNode(span)).to.equal(true, 'span'); }); + + it('returns node itself for two same nodes', function() { + var doc = getDocumentFromXML('
'), + div = doc.root.contents()[0]; + + var siblingParents = doc.getSiblingParents({node1: div, node2: div}); + expect(!!siblingParents.node1 && !!siblingParents.node2).to.equal(true, 'nodes defined'); + expect(siblingParents.node1.sameNode(div)).to.be.equal(true, 'node1'); + expect(siblingParents.node2.sameNode(div)).to.be.equal(true, 'node2'); + }); }); });