Skip to content

Commit

Permalink
filter name tags
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Nov 26, 2024
1 parent cbeba1b commit 8066c80
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)

Check warning on line 13 in planetiler-core/src/main/java/com/onthegomap/planetiler/util/LanguageUtils.java

View workflow job for this annotation

GitHub Actions / Analyze with Sonar

MAJOR CODE_SMELL

Simplify this regular expression to reduce its complexity from 23 to the 20 allowed. rule: java:S5843 (https://sonarcloud.io/organizations/onthegomap/rules?open=java%3AS5843&rule_key=java%3AS5843) issue url: https://sonarcloud.io/project/issues?pullRequest=1115&open=AZNmEL_lkOZ9WbtUH5Ab&id=onthegomap_planetiler
.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 8066c80

Please sign in to comment.