Changeset 19249 in josm


Ignore:
Timestamp:
2024-10-22T19:40:35+02:00 (4 weeks ago)
Author:
taylor.smock
Message:

Fix #23978: Windows does not like paths with multiple :

This fixes an issue where a gpx track with attached images could cause an
exception.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageMetadata.java

    r18592 r19249  
    77import java.io.UncheckedIOException;
    88import java.net.URI;
     9import java.nio.file.FileSystemNotFoundException;
    910import java.time.Instant;
    1011import java.util.List;
     
    262263    /**
    263264     * Extract GPS metadata from image EXIF. Has no effect if the image file is not set
    264      *
     265     * <p>
    265266     * If successful, fills in the LatLon, speed, elevation, image direction, and other attributes
    266267     * @since 18592 (interface), 9270 (GpxImageEntry)
     
    272273        } catch (IOException e) {
    273274            throw new UncheckedIOException(e);
     275        } catch (IllegalArgumentException | FileSystemNotFoundException e) {
     276            throw new UncheckedIOException(new IOException(e));
    274277        }
    275278    }
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/ImageMarkerTest.java

    r18895 r19249  
    77import java.io.File;
    88import java.net.MalformedURLException;
     9import java.net.URI;
     10import java.net.URL;
    911
    1012import org.junit.jupiter.api.AfterEach;
     
    1719import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    1820import org.openstreetmap.josm.testutils.annotations.Main;
     21import org.openstreetmap.josm.tools.PlatformManager;
    1922
    2023/**
     
    6063        assertDoesNotThrow(() -> marker.actionPerformed(null));
    6164    }
     65
     66    /**
     67     * Windows does not like {@code :} to appear multiple times in a path.
     68     * @throws MalformedURLException if the URI fails to create and convert to a URL.
     69     */
     70    @Test
     71    void testNonRegression23978() throws MalformedURLException {
     72        final URL testURL;
     73        if (PlatformManager.isPlatformWindows()) {
     74            // This throws the InvalidPathException (subclass of IllegalArgumentException), and is what the initial problem was.
     75            testURL = URI.create("file:/c:/foo/c:/bar/image.jpg").toURL();
     76        } else {
     77            // This throws an IllegalArgumentException.
     78            testURL = new URL("file:/foobar/image.jpg#hashtagForIAE");
     79        }
     80        ImageMarker imageMarker = new ImageMarker(LatLon.ZERO, testURL,
     81                new MarkerLayer(new GpxData(), null, null, null), 0, 0);
     82        assertDoesNotThrow(() -> imageMarker.actionPerformed(null));
     83    }
    6284}
Note: See TracChangeset for help on using the changeset viewer.