mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-12 16:52:50 +00:00
Return the empty string when calling toOSM() on entities with test IDs
This commit is contained in:
@@ -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] === '-';
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -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('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user