Changeset 15794 in josm


Ignore:
Timestamp:
2020-01-29T20:58:58+01:00 (4 years ago)
Author:
simon04
Message:

see #13901 - Tag2Link: add http:// to website

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Tag2Link.java

    r15711 r15794  
    137137
    138138        // 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);
    142146        }
    143         if (key.matches("^(.+[:_])?source([:_].+)?$") && valueIsURL) {
    144             linkConsumer.acceptLink(getLinkName(value, key), value);
     147        if (key.matches("^(.+[:_])?source([:_].+)?$") && validURL != null) {
     148            linkConsumer.acceptLink(getLinkName(validURL, key), validURL);
    145149        }
    146         if (key.matches("^(.+[:_])?url([:_].+)?$") && valueIsURL) {
    147             linkConsumer.acceptLink(getLinkName(value, key), value);
     150        if (key.matches("^(.+[:_])?url([:_].+)?$") && validURL != null) {
     151            linkConsumer.acceptLink(getLinkName(validURL, key), validURL);
    148152        }
    149         if (key.matches("image") && valueIsURL) {
    150             linkConsumer.acceptLink(tr("View image"), value);
     153        if (key.matches("image") && validURL != null) {
     154            linkConsumer.acceptLink(tr("View image"), validURL);
    151155        }
    152156
  • trunk/test/unit/org/openstreetmap/josm/tools/Tag2LinkTest.java

    r15709 r15794  
    2222    void checkLinks(String... expected) {
    2323        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");
    2439    }
    2540
Note: See TracChangeset for help on using the changeset viewer.