Changeset 6588 in josm for trunk


Ignore:
Timestamp:
2014-01-01T14:10:31+01:00 (11 years ago)
Author:
simon04
Message:

fix #8566 - Improper handling of percent-encoded urls towards Overpass-API (reverts r5782)

Adds DownloadOsmTask#modifyUrlBeforeLoad to allow subclasses to do anything with a to be loaded URL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r6524 r6588  
    55
    66import java.io.IOException;
    7 import java.io.UnsupportedEncodingException;
    87import java.net.URL;
    9 import java.net.URLEncoder;
    108import java.util.ArrayList;
    119import java.util.Collection;
     
    137135    }
    138136
    139     protected final String encodePartialUrl(String url, String safePart) {
    140         if (url != null && safePart != null) {
    141             int pos = url.indexOf(safePart);
    142             if (pos > -1) {
    143                 pos += safePart.length();
    144                 try {
    145                     return url.substring(0, pos) + URLEncoder.encode(url.substring(pos), "UTF-8").replaceAll("\\+", "%20");
    146                 } catch (UnsupportedEncodingException e) {
    147                     e.printStackTrace();
    148                 }
    149             }
    150         }
     137    /**
     138     * This allows subclasses to perform operations on the URL before {@link #loadUrl} is performed.
     139     */
     140    protected String modifyUrlBeforeLoad(String url) {
    151141        return url;
    152142    }
     
    159149    @Override
    160150    public Future<?> loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor) {
    161         if (url.matches(PATTERN_OVERPASS_API_URL)) {
    162             url = encodePartialUrl(url, "/interpreter?data="); // encode only the part after the = sign
    163 
    164         } else if (url.matches(PATTERN_OVERPASS_API_XAPI_URL)) {
    165             url = encodePartialUrl(url, "/xapi?"); // encode only the part after the ? sign
    166         }
     151        url = modifyUrlBeforeLoad(url);
    167152        downloadTask = new DownloadTask(new_layer,
    168153                new OsmServerLocationReader(url),
Note: See TracChangeset for help on using the changeset viewer.