Changeset 5782 in josm for trunk/src


Ignore:
Timestamp:
2013-03-19T01:43:29+01:00 (12 years ago)
Author:
Don-vip
Message:

fix #8505 - Encoding of overpass API URLs (based on patch by roland.olbricht)

File:
1 edited

Legend:

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

    r5730 r5782  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.geom.Area;
    76import java.io.IOException;
     7import java.io.UnsupportedEncodingException;
    88import java.net.URL;
     9import java.net.URLEncoder;
    910import java.util.Collection;
    1011import java.util.concurrent.Future;
    1112import java.util.regex.Matcher;
    1213import java.util.regex.Pattern;
    13 
    14 import org.xml.sax.SAXException;
    1514
    1615import org.openstreetmap.josm.Main;
     
    3029import org.openstreetmap.josm.io.OsmTransferCanceledException;
    3130import org.openstreetmap.josm.io.OsmTransferException;
     31import org.xml.sax.SAXException;
    3232
    3333/**
     
    116116    }
    117117
     118    protected final String encodePartialUrl(String url, String safePart) {
     119        if (url != null && safePart != null) {
     120            int pos = url.indexOf(safePart);
     121            if (pos > -1) {
     122                pos += safePart.length();
     123                try {
     124                    return url.substring(0, pos) + URLEncoder.encode(url.substring(pos), "UTF-8").replaceAll("\\+", "%20");
     125                } catch (UnsupportedEncodingException e) {
     126                    e.printStackTrace();
     127                }
     128            }
     129        }
     130        return url;
     131    }
     132   
    118133    /**
    119134     * Loads a given URL from the OSM Server
     
    122137     */
    123138    public Future<?> loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor) {
     139        if (url.matches(PATTERN_OVERPASS_API_URL)) {
     140            url = encodePartialUrl(url, "/interpreter?data="); // encode only the part after the = sign
     141           
     142        } else if (url.matches(PATTERN_OVERPASS_API_XAPI_URL)) {
     143            url = encodePartialUrl(url, "/xapi?"); // encode only the part after the ? sign
     144        }
    124145        downloadTask = new DownloadTask(new_layer,
    125146                new OsmServerLocationReader(url),
Note: See TracChangeset for help on using the changeset viewer.