From a849d4765ded55173cc10ba3e55a483d281b9174 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 11 Feb 2014 17:09:36 +0100 Subject: [PATCH] smartxml: fix in DocumentNode.getParentSiblings --- src/smartxml/smartxml.js | 8 ++++++-- src/smartxml/smartxml.test.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) 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'); + }); }); }); -- 2.20.1