Changeset 13994 in josm


Ignore:
Timestamp:
2018-07-01T16:09:11+02:00 (3 months ago)
Author:
Don-vip
Message:

fix #16447 - Improve detection of changeset hashtags

Location:
trunk
Files:
2 edited

Legend:

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

    r13109 r13994  
    88
    99import org.openstreetmap.josm.gui.util.ChangeNotifier;
     10import org.openstreetmap.josm.tools.Utils;
    1011
    1112/**
     
    4546     */
    4647    public List<String> findHashTags() {
    47         return Arrays.stream(comment.split("\\s")).filter(s -> s.length() >= 2 && s.charAt(0) == '#').collect(Collectors.toList());
     48        return Arrays.stream(comment.split("\\s"))
     49                .map(s -> Utils.strip(s, ",;"))
     50                .filter(s -> s.matches("#[a-zA-Z][a-zA-Z_\\-0-9]+"))
     51                .collect(Collectors.toList());
    4852    }
    4953}
  • trunk/test/unit/org/openstreetmap/josm/gui/io/ChangesetCommentModelTest.java

    r13109 r13994  
    4040        model.setComment(" https://example.com/#map ");
    4141        assertEquals(Collections.emptyList(), model.findHashTags());
     42        model.setComment("#59606086");
     43        assertEquals(Collections.emptyList(), model.findHashTags());
    4244        model.setComment(" #foo ");
    4345        assertEquals(Arrays.asList("#foo"), model.findHashTags());
    4446        model.setComment(" #foo #bar baz");
    4547        assertEquals(Arrays.asList("#foo", "#bar"), model.findHashTags());
     48        model.setComment(" #foo, #bar, baz");
     49        assertEquals(Arrays.asList("#foo", "#bar"), model.findHashTags());
     50        model.setComment(" #foo; #bar; baz");
     51        assertEquals(Arrays.asList("#foo", "#bar"), model.findHashTags());
     52        model.setComment("#hotosm-project-4773 #DRONEBIRD #OsakaQuake2018 #AOYAMAVISION");
     53        assertEquals(Arrays.asList("#hotosm-project-4773", "#DRONEBIRD", "#OsakaQuake2018", "#AOYAMAVISION"), model.findHashTags());
    4654    }
    4755}
Note: See TracChangeset for help on using the changeset viewer.