Changeset 15994 in josm


Ignore:
Timestamp:
2020-03-02T00:54:04+01:00 (5 months ago)
Author:
simon04
Message:

fix #18741 - Tag checker: report codepoint of unusual Unicode character

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r15888 r15994  
    2323import java.util.Map;
    2424import java.util.Map.Entry;
     25import java.util.OptionalInt;
    2526import java.util.Set;
    2627import java.util.regex.Pattern;
     
    451452
    452453    static boolean containsUnusualUnicodeCharacter(String key, String value) {
    453         return value != null && value.chars().anyMatch(c -> isUnusualUnicodeBlock(key, c));
     454        return getUnusualUnicodeCharacter(key, value).isPresent();
     455    }
     456
     457    static OptionalInt getUnusualUnicodeCharacter(String key, String value) {
     458        return value == null
     459                ? OptionalInt.empty()
     460                : value.chars().filter(c -> isUnusualUnicodeBlock(key, c)).findFirst();
    454461    }
    455462
     
    678685            withErrors.put(p, "ICV");
    679686        }
    680         if ((containsUnusualUnicodeCharacter(key, value)) && !withErrors.contains(p, "UUCV")) {
     687        final OptionalInt unusualUnicodeCharacter = getUnusualUnicodeCharacter(key, value);
     688        if (unusualUnicodeCharacter.isPresent() && !withErrors.contains(p, "UUCV")) {
     689            final String codepoint = String.format(Locale.ROOT, "U+%04X", unusualUnicodeCharacter.getAsInt());
    681690            errors.add(TestError.builder(this, Severity.WARNING, UNUSUAL_UNICODE_CHAR_VALUE)
    682                     .message(tr("Tag value contains unusual Unicode character"), s, key)
     691                    .message(tr("Tag value contains unusual Unicode character {0}", codepoint), s, key)
    683692                    .primitives(p)
    684693                    .build());
Note: See TracChangeset for help on using the changeset viewer.