Changeset 18824 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/UploadDialogModel.java
r18801 r18824 76 76 */ 77 77 String findHashTags(String comment) { 78 String hashtags = Arrays.stream(comment.split("\\s", -1))78 String foundHashtags = Arrays.stream(comment.split("\\s", -1)) 79 79 .map(s -> Utils.strip(s, ",;")) 80 80 .filter(s -> s.matches("#[a-zA-Z0-9][-_a-zA-Z0-9]+")) 81 . collect(Collectors.joining(";"));82 return hashtags.isEmpty() ? null : hashtags;81 .distinct().collect(Collectors.joining(";")); 82 return foundHashtags.isEmpty() ? null : foundHashtags; 83 83 } 84 84 … … 96 96 Set<String> sanitizedHashtags = new LinkedHashSet<>(); 97 97 for (String hashtag : hashtags.split(";", -1)) { 98 sanitizedHashtags.add(hashtag.startsWith("#") ? hashtag : "#" + hashtag); 98 if (comment == null || !comment.contains(hashtag)) { 99 sanitizedHashtags.add(hashtag.startsWith("#") ? hashtag : "#" + hashtag); 100 } 99 101 } 100 102 if (!sanitizedHashtags.isEmpty()) { … … 108 110 /** 109 111 * Inserts/updates/deletes a tag. 110 * 112 * <p> 111 113 * Existing keys are updated. Others are added. A value of {@code null} 112 114 * deletes the key. … … 131 133 /** 132 134 * Inserts/updates/deletes a tag. 133 * 135 * <p> 134 136 * Existing keys are updated. Others are added. A value of {@code null} 135 137 * deletes the key. … … 147 149 /** 148 150 * Inserts/updates/deletes all tags from {@code map}. 149 * 151 * <p> 150 152 * Existing keys are updated. Others are added. A value of {@code null} 151 153 * deletes the key. -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java
r18823 r18824 20 20 import java.util.Set; 21 21 import java.util.regex.Pattern; 22 import java.util.stream.Collectors;23 22 24 23 import javax.swing.AbstractAction; -
trunk/test/unit/org/openstreetmap/josm/gui/io/UploadDialogModelTest.java
r18205 r18824 2 2 package org.openstreetmap.josm.gui.io; 3 3 4 import static org.junit.jupiter.api.Assertions.assert NotNull;4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 5 5 import static org.junit.jupiter.api.Assertions.assertNull; 6 6 import static org.junit.jupiter.api.Assertions.assertEquals; 7 7 8 import org.junit.jupiter.api.extension.RegisterExtension;9 8 import org.junit.jupiter.api.Test; 10 9 11 10 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.testutils. JOSMTestRules;11 import org.openstreetmap.josm.testutils.annotations.Main; 13 12 14 13 /** 15 14 * Unit tests of {@link UploadDialogModel} class. 16 15 */ 17 public class UploadDialogModelTest { 18 /** 19 * Setup tests 20 */ 21 @RegisterExtension 22 public JOSMTestRules test = new JOSMTestRules().preferences().main(); 23 16 @Main 17 class UploadDialogModelTest { 24 18 /** 25 19 * Test of {@link UploadDialogModel}. … … 27 21 @Test 28 22 void testUploadDialogModel() { 29 assert NotNull(new UploadDialogModel());23 assertDoesNotThrow(UploadDialogModel::new); 30 24 } 31 25 … … 65 59 } 66 60 61 @Test 62 void testNonRegression23153() { 63 final DataSet dataSet = new DataSet(); 64 dataSet.getChangeSetTags().put("hashtags", "duplicate"); 65 final UploadDialogModel model = new UploadDialogModel(); 66 final String hashTags = model.findHashTags("#duplicate #duplicate hashtag"); 67 assertEquals("#duplicate", hashTags); 68 final String commentHashtags = UploadDialogModel.addHashTagsFromDataSet("There should be no " + hashTags, dataSet); 69 assertEquals("There should be no #duplicate", commentHashtags); 70 } 71 67 72 }
Note:
See TracChangeset
for help on using the changeset viewer.