mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-17 22:24:49 +02:00
Don't rely on OSM IDs being in range of JS numbers
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user