From 2ac0f1dc26d1c3335f814ec6ea1f0aa97525920d Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 28 Jan 2013 10:15:17 -0500 Subject: [PATCH] Don't rely on OSM IDs being in range of JS numbers --- js/id/graph/entity.js | 6 +++--- test/spec/graph/entity.js | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/js/id/graph/entity.js b/js/id/graph/entity.js index 254607a7b..f91bb89d9 100644 --- a/js/id/graph/entity.js +++ b/js/id/graph/entity.js @@ -20,7 +20,7 @@ iD.Entity.id.fromOSM = function (type, id) { }; iD.Entity.id.toOSM = function (id) { - return +id.slice(1); + return id.slice(1); }; // A function suitable for use as the second argument to d3.selection#data(). @@ -67,11 +67,11 @@ iD.Entity.prototype = { }, created: function() { - return this._updated && this.osmId() < 0; + return this._updated && this.osmId().charAt(0) === '-'; }, modified: function() { - return this._updated && this.osmId() > 0; + return this._updated && this.osmId().charAt(0) !== '-'; }, intersects: function(extent, resolver) { diff --git a/test/spec/graph/entity.js b/test/spec/graph/entity.js index 3f3a701fe..a573f4c8c 100644 --- a/test/spec/graph/entity.js +++ b/test/spec/graph/entity.js @@ -22,13 +22,13 @@ describe('iD.Entity', function () { describe(".fromOSM", function () { it("returns a ID string unique across entity types", function () { - expect(iD.Entity.id.fromOSM('node', 1)).to.equal("n1"); + expect(iD.Entity.id.fromOSM('node', '1')).to.equal("n1"); }); }); describe(".toOSM", function () { it("reverses fromOSM", function () { - expect(iD.Entity.id.toOSM(iD.Entity.id.fromOSM('node', 1))).to.equal(1); + expect(iD.Entity.id.toOSM(iD.Entity.id.fromOSM('node', '1'))).to.equal('1'); }); }); }); @@ -70,10 +70,10 @@ describe('iD.Entity', function () { }); describe("#osmId", function () { - it("returns a numeric osm id", function () { - expect(iD.Entity({id: 'w1234'}).osmId()).to.eql(1234); - expect(iD.Entity({id: 'n1234'}).osmId()).to.eql(1234); - expect(iD.Entity({id: 'r1234'}).osmId()).to.eql(1234); + it("returns an OSM ID as a string", function () { + expect(iD.Entity({id: 'w1234'}).osmId()).to.eql('1234'); + expect(iD.Entity({id: 'n1234'}).osmId()).to.eql('1234'); + expect(iD.Entity({id: 'r1234'}).osmId()).to.eql('1234'); }); });