Changeset 15051 in josm


Ignore:
Timestamp:
2019-05-05T17:35:29+02:00 (5 years ago)
Author:
Don-vip
Message:

see #17634 - allow to define exceptions to the list of forbidden terms, through upload.comment.exception-terms property

Location:
trunk
Files:
2 edited

Legend:

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

    r15040 r15051  
    599599        }
    600600
    601         static String validateUploadTag(String uploadValue, String preferencePrefix, List<String> defMandatory, List<String> defForbidden) {
     601        static String validateUploadTag(String uploadValue, String preferencePrefix,
     602                List<String> defMandatory, List<String> defForbidden, List<String> defException) {
    602603            String uploadValueLc = lower(uploadValue);
    603604            // Check mandatory terms
     
    608609            }
    609610            // Check forbidden terms
     611            List<String> exceptions = Config.getPref().getList(preferencePrefix+".exception-terms", defException);
    610612            List<String> forbiddenTerms = Config.getPref().getList(preferencePrefix+".forbidden-terms", defForbidden)
    611                     .stream().map(UploadAction::lower).filter(uploadValueLc::contains).collect(Collectors.toList());
     613                    .stream().map(UploadAction::lower)
     614                    .filter(x -> uploadValueLc.contains(x) && !exceptions.stream().anyMatch(uploadValueLc::contains))
     615                    .collect(Collectors.toList());
    612616            if (!forbiddenTerms.isEmpty()) {
    613617                return tr("The following forbidden terms have been found: {0}", forbiddenTerms);
     
    624628            final String uploadComment = dialog.getUploadComment();
    625629            final String uploadCommentRejection = validateUploadTag(
    626                     uploadComment, "upload.comment", def, def);
     630                    uploadComment, "upload.comment", def, def, def);
    627631            if ((isUploadCommentTooShort(uploadComment) && warnUploadComment()) ||
    628632                (uploadCommentRejection != null && warnRejectedUploadComment(uploadCommentRejection))) {
     
    633637            final String uploadSource = dialog.getUploadSource();
    634638            final String uploadSourceRejection = validateUploadTag(
    635                     uploadSource, "upload.source", def, def);
     639                    uploadSource, "upload.source", def, def, def);
    636640            if ((Utils.isStripEmpty(uploadSource) && warnUploadSource()) ||
    637641                    (uploadSourceRejection != null && warnRejectedUploadSource(uploadSourceRejection))) {
  • trunk/test/unit/org/openstreetmap/josm/gui/io/UploadDialogTest.java

    r15015 r15051  
    265265        Config.getPref().putList(prefix + ".mandatory-terms", null);
    266266        Config.getPref().putList(prefix + ".forbidden-terms", null);
    267         assertNull(UploadAction.validateUploadTag("foo", prefix, def, def));
     267        assertNull(UploadAction.validateUploadTag("foo", prefix, def, def, def));
    268268
    269269        Config.getPref().putList(prefix + ".mandatory-terms", Arrays.asList("foo"));
    270         assertNull(UploadAction.validateUploadTag("foo", prefix, def, def));
     270        assertNull(UploadAction.validateUploadTag("foo", prefix, def, def, def));
    271271        assertEquals("The following required terms are missing: [foo]",
    272                 UploadAction.validateUploadTag("bar", prefix, def, def));
     272                UploadAction.validateUploadTag("bar", prefix, def, def, def));
    273273
    274274        Config.getPref().putList(prefix + ".forbidden-terms", Arrays.asList("bar"));
    275         assertNull(UploadAction.validateUploadTag("foo", prefix, def, def));
    276         assertEquals("The following forbidden terms have been found: [bar]",
    277                 UploadAction.validateUploadTag("foobar", prefix, def, def));
    278         assertEquals("The following forbidden terms have been found: [bar]",
    279                 UploadAction.validateUploadTag("FOOBAR", prefix, def, def));
     275        assertNull(UploadAction.validateUploadTag("foo", prefix, def, def, def));
     276        assertEquals("The following forbidden terms have been found: [bar]",
     277                UploadAction.validateUploadTag("foobar", prefix, def, def, def));
     278        assertEquals("The following forbidden terms have been found: [bar]",
     279                UploadAction.validateUploadTag("FOOBAR", prefix, def, def, def));
     280
     281        Config.getPref().putList(prefix + ".exception-terms", Arrays.asList("barosm"));
     282        assertEquals("The following forbidden terms have been found: [bar]",
     283                UploadAction.validateUploadTag("foobar", prefix, def, def, def));
     284        assertEquals("The following forbidden terms have been found: [bar]",
     285                UploadAction.validateUploadTag("FOOBAR", prefix, def, def, def));
     286        assertNull(UploadAction.validateUploadTag("foobarosm", prefix, def, def, def));
     287        assertNull(UploadAction.validateUploadTag("FOOBAROSM", prefix, def, def, def));
    280288    }
    281289
Note: See TracChangeset for help on using the changeset viewer.