mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-31 01:09:22 +02:00
protect against relation loops, part 2. fixes #2096
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user