- Timestamp:
- 2014-04-12T11:26:11+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandler.java
r6897 r6972 13 13 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask; 14 14 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 15 import org.openstreetmap.josm.tools.Utils; 15 16 16 17 /** … … 113 114 @Override 114 115 protected void validateRequest() throws RequestHandlerBadRequestException { 115 final String urlString = args.get("url"); 116 String urlString = args.get("url"); 117 if (Main.pref.getBoolean("remotecontrol.importhandler.fix_url_query", true)) { 118 urlString = Utils.fixURLQuery(urlString); 119 } 116 120 try { 117 121 // Ensure the URL is valid -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r6962 r6972 23 23 import java.io.InputStreamReader; 24 24 import java.io.OutputStream; 25 import java.io.UnsupportedEncodingException; 25 26 import java.net.HttpURLConnection; 26 27 import java.net.MalformedURLException; 27 28 import java.net.URL; 28 29 import java.net.URLConnection; 30 import java.net.URLEncoder; 29 31 import java.nio.channels.FileChannel; 30 32 import java.nio.charset.Charset; … … 73 75 private static final int MILLIS_OF_DAY = 86400000; 74 76 77 public static String URL_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;="; 78 75 79 /** 76 80 * Tests whether {@code predicate} applies to at least one elements from {@code collection}. … … 982 986 } 983 987 } 988 989 /** 990 * Fixes URL with illegal characters in the query (and fragment) part by 991 * percent encoding those characters. 992 * 993 * special characters like & and # are not encoded 994 * 995 * @param url the URL that should be fixed 996 * @return the repaired URL 997 */ 998 public static String fixURLQuery(String url) { 999 if (url.indexOf('?') == -1) 1000 return url; 1001 1002 String query = url.substring(url.indexOf('?') + 1); 1003 1004 StringBuilder sb = new StringBuilder(url.substring(0, url.indexOf('?') + 1)); 1005 1006 for (int i=0; i<query.length(); i++) { 1007 String c = query.substring(i, i+1); 1008 if (URL_CHARS.contains(c)) { 1009 sb.append(c); 1010 } else { 1011 try { 1012 sb.append(URLEncoder.encode(c, "UTF-8")); 1013 } catch (UnsupportedEncodingException ex) { 1014 throw new RuntimeException(ex); 1015 } 1016 } 1017 } 1018 return sb.toString(); 1019 } 1020 984 1021 }
Note:
See TracChangeset
for help on using the changeset viewer.