Skip to content

Commit

Permalink
filter name tags (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored Nov 26, 2024
1 parent cbeba1b commit e049876
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class LanguageUtils {
// See https://wiki.openstreetmap.org/wiki/Multilingual_names
public static final Predicate<String> VALID_NAME_TAGS =
Pattern
.compile("^name:[a-z]{2,3}(-[a-z]{4})?([-_](x-)?[a-z]{2,})?(-([a-z]{2}|[0-9]{3}))?$", Pattern.CASE_INSENSITIVE)
.compile("^name:[a-z]{2,3}(-[a-z]{4})?([-_](x-)?[a-z]{2,})?(-([a-z]{2}|\\d{3}))?$", Pattern.CASE_INSENSITIVE)
.asMatchPredicate();
// See https://github.com/onthegomap/planetiler/issues/86
// Match strings that only contain latin characters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public Map<String, String> getNameTranslations(Map<String, Object> tags) {
Map<String, String> result = new HashMap<>();
for (var entry : tags.entrySet()) {
String key = entry.getKey();
if (key.startsWith("name:") && entry.getValue() instanceof String stringVal) {
if (LanguageUtils.isValidOsmNameTag(key) && entry.getValue() instanceof String stringVal) {
result.put(key, stringVal);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ void testNull() {
assertEquals(Map.of(), translations.getTranslations(Map.of("name:en", "name")));
}

@Test
void testWildcard() {
var translations = Translations.defaultProvider(List.of("*"));
assertEquals(Map.of("name:en", "name"), translations.getTranslations(Map.of("name:en", "name")));
assertEquals(Map.of("name:sr-Latn", "name"), translations.getTranslations(Map.of("name:sr-Latn", "name")));
assertEquals(Map.of("name:zh-Hant-TW", "name"), translations.getTranslations(Map.of("name:zh-Hant-TW", "name")));
assertEquals(Map.of(), translations.getTranslations(Map.of("name:left", "name")));
assertEquals(Map.of(), translations.getTranslations(Map.of("name:etymology:wikidata", "name")));
}

@Test
void testDefaultProvider() {
var translations = Translations.defaultProvider(List.of("en"));
Expand Down

0 comments on commit e049876

Please sign in to comment.