Changeset 17736 in josm for trunk/src


Ignore:
Timestamp:
2021-04-09T23:18:01+02:00 (4 years ago)
Author:
simon04
Message:

fix #19771 - Tag2Link: use percent encoding for Wikimedia Commons URLs

File:
1 edited

Legend:

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

    r17735 r17736  
    2727import javax.json.JsonValue;
    2828
     29import com.google.gdata.util.common.base.PercentEscaper;
    2930import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    3031import org.openstreetmap.josm.data.osm.OsmUtils;
     
    202203        if (key.matches("wikimedia_commons|image") && value.matches("(?i:File):.*")) {
    203204            OsmUtils.splitMultipleValues(value).forEach(i -> linkConsumer.acceptLink(
    204                     tr("View image on Wikimedia Commons"), "https://commons.wikimedia.org/wiki/" + i, imageResource.get()));
     205                    tr("View image on Wikimedia Commons"), getWikimediaCommonsUrl(i), imageResource.get()));
    205206        }
    206207        if (key.matches("wikimedia_commons|image") && value.matches("(?i:Category):.*")) {
    207208            OsmUtils.splitMultipleValues(value).forEach(i -> linkConsumer.acceptLink(
    208                     tr("View category on Wikimedia Commons"), "https://commons.wikimedia.org/wiki/" + i, imageResource.get()));
     209                    tr("View category on Wikimedia Commons"), getWikimediaCommonsUrl(i), imageResource.get()));
    209210        }
    210211
     
    216217    }
    217218
     219    private static String getWikimediaCommonsUrl(String i) {
     220        return "https://commons.wikimedia.org/wiki/" + new PercentEscaper(PercentEscaper.SAFEPATHCHARS_URLENCODER, false).escape(i);
     221    }
     222
    218223    private static String getLinkName(String url, String fallback) {
    219224        return tr("Open {0}", getHost(url, fallback));
Note: See TracChangeset for help on using the changeset viewer.