Changeset 17735 in josm
- Timestamp:
- 2021-04-09T23:02:40+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Tag2Link.java
r17627 r17735 14 14 import java.util.List; 15 15 import java.util.Map; 16 import java.util.Objects; 16 17 import java.util.Optional; 17 18 import java.util.function.Supplier; … … 160 161 161 162 // Common 162 final String validURL = value.startsWith("http:") || value.startsWith("https:") 163 ? value 164 : value.startsWith("www.") 165 ? "http://" + value 166 : null; 167 if (key.matches("^(.+[:_])?website([:_].+)?$") && validURL != null) { 168 linkConsumer.acceptLink(getLinkName(validURL, key), validURL, imageResource.get()); 169 } 170 if (key.matches("^(.+[:_])?source([:_].+)?$") && validURL != null) { 171 linkConsumer.acceptLink(getLinkName(validURL, key), validURL, imageResource.get()); 172 } 173 if (key.matches("^(.+[:_])?url([:_].+)?$") && validURL != null) { 174 linkConsumer.acceptLink(getLinkName(validURL, key), validURL, imageResource.get()); 175 } 176 if (key.matches("image") && validURL != null) { 177 linkConsumer.acceptLink(tr("View image"), validURL, imageResource.get()); 163 final List<String> validURLs = value.startsWith("http:") || value.startsWith("https:") || value.startsWith("www.") 164 ? OsmUtils.splitMultipleValues(value) 165 .map(v -> v.startsWith("http:") || v.startsWith("https:") 166 ? v 167 : v.startsWith("www.") 168 ? "http://" + v 169 : null) 170 .filter(Objects::nonNull) 171 .collect(Collectors.toList()) 172 : Collections.emptyList(); 173 if (key.matches("^(.+[:_])?website([:_].+)?$") && !validURLs.isEmpty()) { 174 validURLs.forEach(validURL -> linkConsumer.acceptLink(getLinkName(validURL, key), validURL, imageResource.get())); 175 } 176 if (key.matches("^(.+[:_])?source([:_].+)?$") && !validURLs.isEmpty()) { 177 validURLs.forEach(validURL -> linkConsumer.acceptLink(getLinkName(validURL, key), validURL, imageResource.get())); 178 } 179 if (key.matches("^(.+[:_])?url([:_].+)?$") && !validURLs.isEmpty()) { 180 validURLs.forEach(validURL -> linkConsumer.acceptLink(getLinkName(validURL, key), validURL, imageResource.get())); 181 } 182 if (key.matches("image") && !validURLs.isEmpty()) { 183 validURLs.forEach(validURL -> linkConsumer.acceptLink(tr("View image"), validURL, imageResource.get())); 178 184 } 179 185 -
trunk/test/unit/org/openstreetmap/josm/tools/Tag2LinkTest.java
r17275 r17735 123 123 } 124 124 125 /** 126 * Unit test of function {@link Tag2Link#getLinksForTag}. 127 * 128 * Non-regression test for https://josm.openstreetmap.de/ticket/19754#comment:9 129 */ 130 @Test 131 void testMultipleSources() { 132 Tag2Link.getLinksForTag("source", "https://foo.com/; https://bar.com/; https://baz.com/", this::addLink); 133 checkLinks("Open foo.com // https://foo.com/", 134 "Open bar.com // https://bar.com/", 135 "Open baz.com // https://baz.com/"); 136 } 137 125 138 }
Note:
See TracChangeset
for help on using the changeset viewer.