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

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

File:
1 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))) {
Note: See TracChangeset for help on using the changeset viewer.