diff --git a/stream/tag_mapper.js b/stream/tag_mapper.js index 816062d8..788bef59 100644 --- a/stream/tag_mapper.js +++ b/stream/tag_mapper.js @@ -43,7 +43,7 @@ module.exports = function(){ if (trimmed_value) { if (!trimmed_name ) { doc.setName('default', trim( tags[key])); - } else { + } else if(!trimmed_name.includes(trimmed_value)) { doc.setNameAlias('default', trim( tags[key])); } } diff --git a/test/stream/tag_mapper.js b/test/stream/tag_mapper.js index 0c1bb9f6..55e445f6 100644 --- a/test/stream/tag_mapper.js +++ b/test/stream/tag_mapper.js @@ -112,6 +112,38 @@ module.exports.tests.osm_names = function(test, common) { }); }; +// Reject alt names that are a substring of the main name +module.exports.tests.substring_alt_name = function(test, common) { + var doc = new Document('a','b',1); + doc.setMeta('tags', { 'name': 'test place', 'alt_name': 'test pl' }); + + test('rejects - substring alt name', function(t) { + var stream = mapper(); + stream.pipe( through.obj( function( doc, enc, next ){ + t.deepEqual(doc.name, { default: 'test place' }, 'substring name removed'); + t.end(); // test will fail if not called (or called twice). + next(); + })); + stream.write(doc); + }); +}; + +// Reject alt names that are a substring of the main name, even if they appear before the name in list of tags +module.exports.tests.substring_alt_name2 = function(test, common) { + var doc = new Document('a','b',1); + doc.setMeta('tags', { 'alt_name': 'test pl', name: 'test place'}); + + test('rejects - substring alt name', function(t) { + var stream = mapper(); + stream.pipe( through.obj( function( doc, enc, next ){ + t.deepEqual(doc.name, { default: 'test place' }, 'substring name removed'); + t.end(); // test will fail if not called (or called twice). + next(); + })); + stream.write(doc); + }); +}; + // Cover the case of a tag key being 'name:' eg. { 'name:': 'foo' } // Not to be confused with { 'name': 'foo' } (note the extraneous colon) module.exports.tests.extraneous_colon = function(test, common) {