protect against relation loops, part 2. fixes #2096

This commit is contained in:
tyr
2014-01-10 10:50:50 +01:00
parent b1bffb5037
commit b71c98cfca
2 changed files with 21 additions and 2 deletions

View File

@@ -18,7 +18,11 @@ iD.Tree = function(head) {
return rect;
}
function updateParents(entity, insertions) {
function updateParents(entity, insertions, memo) {
if (memo && memo[entity.id]) return;
memo = memo || {};
memo[entity.id] = true;
head.parentWays(entity).forEach(function(parent) {
if (rectangles[parent.id]) {
rtree.remove(rectangles[parent.id]);
@@ -31,7 +35,7 @@ iD.Tree = function(head) {
rtree.remove(rectangles[parent.id]);
insertions.push(parent);
}
updateParents(parent, insertions);
updateParents(parent, insertions, memo);
});
}

View File

@@ -41,6 +41,21 @@ describe("iD.Tree", function() {
expect(tree.intersects(iD.geo.Extent([0, 0], [2, 2]), g)).to.eql([]);
expect(tree.intersects(iD.geo.Extent([0, 0], [11, 11]), g)).to.eql([node_]);
});
it("does not error on self-referencing relations", function() {
var graph = iD.Graph(),
tree = iD.Tree(graph),
node = iD.Node({id: 'n', loc: [1, 1]}),
relation = iD.Relation();
relation = relation.addMember({id: node.id});
relation = relation.addMember({id: relation.id});
graph.rebase([node, relation], [graph]);
tree.rebase([relation]);
expect(tree.intersects(iD.geo.Extent([0, 0], [2, 2]), graph)).to.eql([relation]);
});
});
describe("#intersects", function() {