Changeset 15794 in josm
- Timestamp:
- 2020-01-29T20:58:58+01:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Tag2Link.java
r15711 r15794 137 137 138 138 // Common 139 final boolean valueIsURL = value.matches("^(http:|https:|www\\.).*"); 140 if (key.matches("^(.+[:_])?website([:_].+)?$") && valueIsURL) { 141 linkConsumer.acceptLink(getLinkName(value, key), value); 139 final String validURL = value.startsWith("http:") || value.startsWith("https:") 140 ? value 141 : value.startsWith("www.") 142 ? "http://" + value 143 : null; 144 if (key.matches("^(.+[:_])?website([:_].+)?$") && validURL != null) { 145 linkConsumer.acceptLink(getLinkName(validURL, key), validURL); 142 146 } 143 if (key.matches("^(.+[:_])?source([:_].+)?$") && val ueIsURL) {144 linkConsumer.acceptLink(getLinkName(val ue, key), value);147 if (key.matches("^(.+[:_])?source([:_].+)?$") && validURL != null) { 148 linkConsumer.acceptLink(getLinkName(validURL, key), validURL); 145 149 } 146 if (key.matches("^(.+[:_])?url([:_].+)?$") && val ueIsURL) {147 linkConsumer.acceptLink(getLinkName(val ue, key), value);150 if (key.matches("^(.+[:_])?url([:_].+)?$") && validURL != null) { 151 linkConsumer.acceptLink(getLinkName(validURL, key), validURL); 148 152 } 149 if (key.matches("image") && val ueIsURL) {150 linkConsumer.acceptLink(tr("View image"), val ue);153 if (key.matches("image") && validURL != null) { 154 linkConsumer.acceptLink(tr("View image"), validURL); 151 155 } 152 156 -
trunk/test/unit/org/openstreetmap/josm/tools/Tag2LinkTest.java
r15709 r15794 22 22 void checkLinks(String... expected) { 23 23 Assert.assertEquals(Arrays.asList(expected), links); 24 } 25 26 /** 27 * Unit test of function {@link Tag2Link#getLinksForTag}. 28 */ 29 @Test 30 public void testWebsite() { 31 Tag2Link.getLinksForTag("website", "http://www.openstreetmap.org/", this::addLink); 32 checkLinks("Open www.openstreetmap.org // http://www.openstreetmap.org/"); 33 links.clear(); 34 Tag2Link.getLinksForTag("website", "https://www.openstreetmap.org/", this::addLink); 35 checkLinks("Open www.openstreetmap.org // https://www.openstreetmap.org/"); 36 links.clear(); 37 Tag2Link.getLinksForTag("website", "www.openstreetmap.org", this::addLink); 38 checkLinks("Open www.openstreetmap.org // http://www.openstreetmap.org"); 24 39 } 25 40
Note:
See TracChangeset
for help on using the changeset viewer.