diff --git a/js/id/actions/split_way.js b/js/id/actions/split_way.js index 6db8b57e0..6fbd08595 100644 --- a/js/id/actions/split_way.js +++ b/js/id/actions/split_way.js @@ -47,7 +47,8 @@ iD.actions.SplitWay = function(nodeId, newWayId) { j; for (j = 0; j < relation.members.length; j++) { - if (relation.members[j].type === 'way' && graph.entity(relation.members[j].id).contains(last)) { + var entity = graph.entity(relation.members[j].id); + if (entity && entity.type === 'way' && entity.contains(last)) { break; } } diff --git a/test/spec/actions/split_way.js b/test/spec/actions/split_way.js index 6074cbaa8..2958521a9 100644 --- a/test/spec/actions/split_way.js +++ b/test/spec/actions/split_way.js @@ -175,6 +175,20 @@ describe("iD.actions.SplitWay", function () { expect(_.pluck(graph.entity('r').members, 'id')).to.eql(['~', '=', '-']); }); + it("handles incomplete relations", function () { + var graph = iD.Graph({ + 'a': iD.Node({id: 'a'}), + 'b': iD.Node({id: 'b'}), + 'c': iD.Node({id: 'c'}), + '-': iD.Way({id: '-', nodes: ['a', 'b', 'c']}), + 'r': iD.Relation({id: 'r', members: [{id: '~', type: 'way'}, {id: '-', type: 'way'}]}) + }); + + graph = iD.actions.SplitWay('b', '=')(graph); + + expect(_.pluck(graph.entity('r').members, 'id')).to.eql(['~', '-', '=']); + }); + ['restriction', 'restriction:bus'].forEach(function (type) { it("updates a restriction's 'from' role", function () { // Situation: