Changeset 15015 in josm


Ignore:
Timestamp:
2019-04-22T16:43:22+02:00 (4 weeks ago)
Author:
Don-vip
Message:

see #17634 - use case insensitive comparison, forbid google as source

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r15010 r15015  
    2323import java.util.Iterator;
    2424import java.util.List;
     25import java.util.Locale;
    2526import java.util.Map;
    2627import java.util.Map.Entry;
     
    581582
    582583        static boolean isUploadCommentTooShort(String comment) {
    583             String s = comment.trim();
     584            String s = Utils.strip(comment);
    584585            boolean result = true;
    585586            if (!s.isEmpty()) {
     
    594595        }
    595596
    596         static String validateUploadTag(String uploadValue, String preferencePrefix) {
     597        private static String lc(String s) {
     598            return s.toLowerCase(Locale.ENGLISH);
     599        }
     600
     601        static String validateUploadTag(String uploadValue, String preferencePrefix, List<String> defMandatory, List<String> defForbidden) {
     602            String uploadValueLc = lc(uploadValue);
    597603            // Check mandatory terms
    598             List<String> missingTerms = Config.getPref().getList(preferencePrefix+".mandatory-terms")
    599                 .stream().filter(x -> !uploadValue.contains(x)).collect(Collectors.toList());
     604            List<String> missingTerms = Config.getPref().getList(preferencePrefix+".mandatory-terms", defMandatory)
     605                .stream().map(UploadAction::lc).filter(x -> !uploadValueLc.contains(x)).collect(Collectors.toList());
    600606            if (!missingTerms.isEmpty()) {
    601607                return tr("The following required terms are missing: {0}", missingTerms);
    602608            }
    603609            // Check forbidden terms
    604             List<String> forbiddenTerms = Config.getPref().getList(preferencePrefix+".forbidden-terms")
    605                     .stream().filter(uploadValue::contains).collect(Collectors.toList());
     610            List<String> forbiddenTerms = Config.getPref().getList(preferencePrefix+".forbidden-terms", defForbidden)
     611                    .stream().map(UploadAction::lc).filter(uploadValueLc::contains).collect(Collectors.toList());
    606612            if (!forbiddenTerms.isEmpty()) {
    607613                return tr("The following forbidden terms have been found: {0}", forbiddenTerms);
     
    615621            dialog.forceUpdateActiveField();
    616622
     623            final List<String> def = Collections.emptyList();
    617624            final String uploadComment = dialog.getUploadComment();
    618             final String uploadCommentRejection = validateUploadTag(uploadComment, "upload.comment");
     625            final String uploadCommentRejection = validateUploadTag(
     626                    uploadComment, "upload.comment", def, def);
    619627            if ((isUploadCommentTooShort(uploadComment) && warnUploadComment()) ||
    620628                (uploadCommentRejection != null && warnRejectedUploadComment(uploadCommentRejection))) {
     
    624632            }
    625633            final String uploadSource = dialog.getUploadSource();
    626             final String uploadSourceRejection = validateUploadTag(uploadSource, "upload.source");
     634            final String uploadSourceRejection = validateUploadTag(
     635                    uploadSource, "upload.source", def, Collections.singletonList("google"));
    627636            if ((Utils.isStripEmpty(uploadSource) && warnUploadSource()) ||
    628637                    (uploadSourceRejection != null && warnRejectedUploadSource(uploadSourceRejection))) {
  • trunk/test/unit/org/openstreetmap/josm/gui/io/UploadDialogTest.java

    r15013 r15015  
    99import java.awt.GraphicsEnvironment;
    1010import java.util.Arrays;
     11import java.util.Collections;
    1112import java.util.List;
    1213import java.util.Map;
     
    261262
    262263    private static void doTestValidateUploadTag(String prefix) {
     264        List<String> def = Collections.emptyList();
    263265        Config.getPref().putList(prefix + ".mandatory-terms", null);
    264266        Config.getPref().putList(prefix + ".forbidden-terms", null);
    265         assertNull(UploadAction.validateUploadTag("foo", prefix));
     267        assertNull(UploadAction.validateUploadTag("foo", prefix, def, def));
    266268
    267269        Config.getPref().putList(prefix + ".mandatory-terms", Arrays.asList("foo"));
    268         assertNull(UploadAction.validateUploadTag("foo", prefix));
     270        assertNull(UploadAction.validateUploadTag("foo", prefix, def, def));
    269271        assertEquals("The following required terms are missing: [foo]",
    270                 UploadAction.validateUploadTag("bar", prefix));
     272                UploadAction.validateUploadTag("bar", prefix, def, def));
    271273
    272274        Config.getPref().putList(prefix + ".forbidden-terms", Arrays.asList("bar"));
    273         assertNull(UploadAction.validateUploadTag("foo", prefix));
     275        assertNull(UploadAction.validateUploadTag("foo", prefix, def, def));
    274276        assertEquals("The following forbidden terms have been found: [bar]",
    275                 UploadAction.validateUploadTag("foobar", prefix));
     277                UploadAction.validateUploadTag("foobar", prefix, def, def));
     278        assertEquals("The following forbidden terms have been found: [bar]",
     279                UploadAction.validateUploadTag("FOOBAR", prefix, def, def));
    276280    }
    277281
Note: See TracChangeset for help on using the changeset viewer.