diff --git a/modules/osm/entity.js b/modules/osm/entity.js index 7212443de..5636fdc78 100644 --- a/modules/osm/entity.js +++ b/modules/osm/entity.js @@ -36,7 +36,11 @@ osmEntity.id.fromOSM = function(type, id) { osmEntity.id.toOSM = function(id) { - return id.slice(1); + var match = id.match(/^[cnwr](-?\d+)$/); + if (match) { + return match[1]; + } + return ''; }; @@ -129,7 +133,8 @@ osmEntity.prototype = { isNew: function() { - return this.osmId() < 0; + var osmId = osmEntity.id.toOSM(this.id); + return osmId.length === 0 || osmId[0] === '-'; }, diff --git a/test/spec/osm/entity.js b/test/spec/osm/entity.js index cbc81833d..95f440c9a 100644 --- a/test/spec/osm/entity.js +++ b/test/spec/osm/entity.js @@ -32,6 +32,11 @@ describe('iD.osmEntity', function () { describe('.toOSM', function () { it('reverses fromOSM', function () { expect(iD.osmEntity.id.toOSM(iD.osmEntity.id.fromOSM('node', '1'))).to.equal('1'); + expect(iD.osmEntity.id.toOSM(iD.osmEntity.id.fromOSM('node', '-1'))).to.equal('-1'); + }); + + it('returns the empty string for other strings', function () { + expect(iD.osmEntity.id.toOSM('a')).to.equal(''); }); }); });