Return the empty string when calling toOSM() on entities with test IDs

This commit is contained in:
Thomas Petillon
2020-04-11 16:26:17 +02:00
parent fab6dfa3dd
commit 7a1d08f80e
2 changed files with 12 additions and 2 deletions

View File

@@ -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] === '-';
},

View File

@@ -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('');
});
});
});