Changeset 6474 in josm for trunk


Ignore:
Timestamp:
2013-12-16T00:22:44+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9434 - Robustness in hash URLs parsing

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/.settings/org.eclipse.jdt.ui.prefs

    r2899 r6474  
    1 #Wed Jan 27 11:53:40 EST 2010
    21cleanup_settings_version=2
    32eclipse.preferences.version=1
     
    1413sp_cleanup.add_missing_nls_tags=false
    1514sp_cleanup.add_missing_override_annotations=true
     15sp_cleanup.add_missing_override_annotations_interface_methods=false
    1616sp_cleanup.add_serial_version_id=false
    1717sp_cleanup.always_use_blocks=false
     
    5151sp_cleanup.sort_members=false
    5252sp_cleanup.sort_members_all=false
    53 sp_cleanup.use_blocks=true
     53sp_cleanup.use_blocks=false
    5454sp_cleanup.use_blocks_only_for_return_and_throw=true
    5555sp_cleanup.use_parentheses_in_expressions=false
  • trunk/src/org/openstreetmap/josm/Main.java

    r6471 r6474  
    212212     */
    213213    public static int logLevel = 3;
    214    
     214
    215215    /**
    216216     * Prints an error message if logging is on.
     
    223223        System.err.println(tr("ERROR: {0}", msg));
    224224    }
    225    
     225
    226226    /**
    227227     * Prints a warning message if logging is on.
     
    233233        System.err.println(tr("WARNING: {0}", msg));
    234234    }
    235    
     235
    236236    /**
    237237     * Prints an informational message if logging is on.
     
    243243        System.out.println(tr("INFO: {0}", msg));
    244244    }
    245    
     245
    246246    /**
    247247     * Prints a debug message if logging is on.
     
    253253        System.out.println(tr("DEBUG: {0}", msg));
    254254    }
    255    
     255
    256256    /**
    257257     * Prints a formated error message if logging is on. Calls {@link MessageFormat#format}
     
    264264        error(MessageFormat.format(msg, objects));
    265265    }
    266    
     266
    267267    /**
    268268     * Prints a formated warning message if logging is on. Calls {@link MessageFormat#format}
     
    274274        warn(MessageFormat.format(msg, objects));
    275275    }
    276    
     276
    277277    /**
    278278     * Prints a formated informational message if logging is on. Calls {@link MessageFormat#format}
     
    284284        info(MessageFormat.format(msg, objects));
    285285    }
    286    
     286
    287287    /**
    288288     * Prints a formated debug message if logging is on. Calls {@link MessageFormat#format}
     
    294294        debug(MessageFormat.format(msg, objects));
    295295    }
    296    
     296
    297297    /**
    298298     * Prints an error message for the given Throwable.
     
    303303        error(getErrorMessage(t));
    304304    }
    305    
     305
    306306    /**
    307307     * Prints a warning message for the given Throwable.
     
    312312        warn(getErrorMessage(t));
    313313    }
    314    
     314
    315315    private static String getErrorMessage(Throwable t) {
    316316        StringBuilder sb = new StringBuilder(t.getClass().getName());
     
    318318        if (msg != null) {
    319319            sb.append(": ").append(msg.trim());
     320        }
     321        Throwable cause = t.getCause();
     322        if (cause != null && !cause.equals(t)) {
     323            sb.append(". ").append(tr("Cause: ")).append(getErrorMessage(cause));
    320324        }
    321325        return sb.toString();
  • trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java

    r6380 r6474  
    183183        if (!tasks.isEmpty()) {
    184184            // TODO: handle multiple suitable tasks ?
    185             future = tasks.iterator().next().loadUrl(new_layer, url, monitor);
     185            try {
     186                future = tasks.iterator().next().loadUrl(new_layer, url, monitor);
     187            } catch (IllegalArgumentException e) {
     188                Main.error(e);
     189            }
    186190        }
    187191        if (future != null) {
  • trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r6380 r6474  
    1111import org.openstreetmap.josm.data.osm.DataSet;
    1212import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     13import org.openstreetmap.josm.tools.CheckParameterUtil;
    1314import org.openstreetmap.josm.tools.Utils;
    1415import org.xml.sax.SAXException;
     
    3435     */
    3536    public BoundingBoxDownloader(Bounds downloadArea) {
     37        CheckParameterUtil.ensureParameterNotNull(downloadArea, "downloadArea");
    3638        this.lat1 = downloadArea.getMinLat();
    3739        this.lon1 = downloadArea.getMinLon();
  • trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java

    r6453 r6474  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import java.awt.HeadlessException;
     
    1517public final class OsmUrlToBounds {
    1618    private static final String SHORTLINK_PREFIX = "http://osm.org/go/";
    17    
     19
    1820    private OsmUrlToBounds() {
    1921        // Hide default constructor for utils classes
    2022    }
    2123
    22     public static Bounds parse(String url) {
     24    public static Bounds parse(String url) throws IllegalArgumentException {
    2325        try {
    2426            // a percent sign indicates an encoded URL (RFC 1738).
     
    8688     * @param url string for parsing
    8789     * @return Bounds if hashurl, {@code null} otherwise
    88      */
    89     private static Bounds parseHashURLs(String url) {
     90     * @throws IllegalArgumentException if URL is invalid
     91     */
     92    private static Bounds parseHashURLs(String url) throws IllegalArgumentException {
    9093        int startIndex = url.indexOf("#map=");
    9194        if (startIndex == -1) return null;
    9295        int endIndex = url.indexOf('&', startIndex);
    9396        if (endIndex == -1) endIndex = url.length();
    94         try {
    95             String coordPart = url.substring(startIndex+5, endIndex);
    96             String[] parts = coordPart.split("/");
    97             Bounds b = positionToBounds(Double.parseDouble(parts[1]),
    98                     Double.parseDouble(parts[2]),
    99                     Integer.parseInt(parts[0]));
    100             return b;
    101         } catch (Exception ex) {
    102             Main.debug(ex.getMessage());
    103             return null;
    104         }
     97        String coordPart = url.substring(startIndex+5, endIndex);
     98        String[] parts = coordPart.split("/");
     99        if (parts.length < 3) {
     100            throw new IllegalArgumentException(tr("URL does not contain {0}/{1}/{2}", tr("zoom"), tr("latitude"), tr("longitude")));
     101        }
     102        int zoom;
     103        double lat, lon;
     104        try {
     105            zoom = Integer.parseInt(parts[0]);
     106        } catch (NumberFormatException e) {
     107            throw new IllegalArgumentException(tr("URL does not contain valid {0}", tr("zoom")), e);
     108        }
     109        try {
     110            lat = Double.parseDouble(parts[1]);
     111        } catch (NumberFormatException e) {
     112            throw new IllegalArgumentException(tr("URL does not contain valid {0}", tr("latitude")), e);
     113        }
     114        try {
     115            lon = Double.parseDouble(parts[2]);
     116        } catch (NumberFormatException e) {
     117            throw new IllegalArgumentException(tr("URL does not contain valid {0}", tr("longitude")), e);
     118        }
     119        return positionToBounds(lat, lon, zoom);
    105120    }
    106121
Note: See TracChangeset for help on using the changeset viewer.