Skip to content

Commit

Permalink
Fix #23978: Windows does not like paths with multiple :
Browse files Browse the repository at this point in the history
This fixes an issue where a gpx track with attached images could cause an
exception.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@19249 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Oct 22, 2024
1 parent fbf6d70 commit 552caa5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URI;
import java.nio.file.FileSystemNotFoundException;
import java.time.Instant;
import java.util.List;

Expand Down Expand Up @@ -261,7 +262,7 @@ default Integer getExifOrientation() {

/**
* Extract GPS metadata from image EXIF. Has no effect if the image file is not set
*
* <p>
* If successful, fills in the LatLon, speed, elevation, image direction, and other attributes
* @since 18592 (interface), 9270 (GpxImageEntry)
*/
Expand All @@ -271,6 +272,8 @@ default void extractExif() {
ImageUtils.applyExif(this, bufferedInputStream);
} catch (IOException e) {
throw new UncheckedIOException(e);
} catch (IllegalArgumentException | FileSystemNotFoundException e) {
throw new UncheckedIOException(new IOException(e));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
Expand All @@ -16,6 +18,7 @@
import org.openstreetmap.josm.gui.layer.geoimage.ImageViewerDialog;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.testutils.annotations.Main;
import org.openstreetmap.josm.tools.PlatformManager;

/**
* Unit tests of {@link ImageMarker} class.
Expand Down Expand Up @@ -59,4 +62,23 @@ void testTicket22638() throws MalformedURLException {
1d, 2d);
assertDoesNotThrow(() -> marker.actionPerformed(null));
}

/**
* Windows does not like {@code :} to appear multiple times in a path.
* @throws MalformedURLException if the URI fails to create and convert to a URL.
*/
@Test
void testNonRegression23978() throws MalformedURLException {
final URL testURL;
if (PlatformManager.isPlatformWindows()) {
// This throws the InvalidPathException (subclass of IllegalArgumentException), and is what the initial problem was.
testURL = URI.create("file:/c:/foo/c:/bar/image.jpg").toURL();
} else {
// This throws an IllegalArgumentException.
testURL = new URL("file:/foobar/image.jpg#hashtagForIAE");
}
ImageMarker imageMarker = new ImageMarker(LatLon.ZERO, testURL,
new MarkerLayer(new GpxData(), null, null, null), 0, 0);
assertDoesNotThrow(() -> imageMarker.actionPerformed(null));
}
}

0 comments on commit 552caa5

Please sign in to comment.