Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly process alt_name tag when there are multiple entries separated by semicolon #581

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,16 @@ module.exports = function(){
if( key === NAME_SCHEMA._primary ){
doc.setName( NAME_SCHEMA[key], val2 );
} else if ( 'default' === NAME_SCHEMA[key] ) {
doc.setNameAlias( NAME_SCHEMA[key], val2 );
// `alt_name` may contain multiple names separated by semicolons
// (see https://wiki.openstreetmap.org/wiki/Key:alt_name#Examples)
if (key === 'alt_name') {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh at glance it seems to be better to "bake" the fact that we need to split by something to NAME_SCHEMA, but it seems to be a bit of over-engineering for now (but let me know :) )

const altNames = val2.split(';');
altNames.forEach((altName) => {
doc.setNameAlias( NAME_SCHEMA[key], altName );
});
} else {
doc.setNameAlias( NAME_SCHEMA[key], val2 );
}
} else {
doc.setName( NAME_SCHEMA[key], val2 );
}
Expand Down
27 changes: 27 additions & 0 deletions test/stream/tag_mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,33 @@ module.exports.tests.osm_names = function(test, common) {
t.end(); // test will fail if not called (or called twice).
next();
}));

stream.write(doc);
});

test('maps - name aliases - multiple alt_names', function(t) {
var doc = new Document('a','b',1);
doc.setMeta('tags', {
loc_name: 'loc_name',
nat_name: 'nat_name',
int_name: 'int_name',
name: 'name',
alt_name: 'alt_name;alt_name2',
official_name: 'official_name',
old_name: 'old_name',
reg_name: 'reg_name',
short_name: 'short_name',
sorting_name: 'sorting_name'
});
var stream = mapper();
stream.pipe( through.obj( function( doc, enc, next ){
t.equal(doc.getName('default'), 'name', 'correctly mapped');
t.deepEqual(doc.getNameAliases('default'), ['loc_name','alt_name','alt_name2','short_name'], 'correctly mapped');

t.end(); // test will fail if not called (or called twice).
next();
}));

stream.write(doc);
});
};
Expand Down