Ticket #20310: 20310.patch
| File 20310.patch, 2.4 KB (added by , 5 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/io/importexport/JpgImporter.java
10 10 import java.util.HashSet; 11 11 import java.util.List; 12 12 import java.util.Set; 13 import java.util.regex.Matcher; 14 import java.util.regex.Pattern; 13 15 14 16 import org.openstreetmap.josm.actions.ExtensionFileFilter; 15 17 import org.openstreetmap.josm.gui.layer.GpxLayer; 16 18 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; 17 19 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 20 import org.openstreetmap.josm.io.CachedFile; 18 21 import org.openstreetmap.josm.io.IllegalDataException; 19 22 20 23 /** … … 22 25 * 23 26 */ 24 27 public class JpgImporter extends FileImporter { 28 /** Check if the filename starts with a borked path ({@link java.io.File#File} drops consecutive {@code /} characters). */ 29 private static final Pattern URL_START_BAD = Pattern.compile("^(https?:/)([^/].*)$"); 30 /** Check for the beginning of a "good" url */ 31 private static final Pattern URL_START_GOOD = Pattern.compile("^https?://.*$"); 32 25 33 private GpxLayer gpx; 26 34 27 35 /** … … 106 114 progressMonitor.worked(1); 107 115 } 108 116 } else { 109 if (FILE_FILTER.accept(f)) { 117 /* Check if the path is a web path, and if so, ensure that it is "correct" */ 118 final String path = f.getPath(); 119 Matcher matcherBad = URL_START_BAD.matcher(path); 120 final String realPath; 121 if (matcherBad.matches()) { 122 realPath = matcherBad.replaceFirst(matcherBad.group(1) + "/" + matcherBad.group(2)); 123 } else { 124 realPath = path; 125 } 126 if (URL_START_GOOD.matcher(realPath).matches() && FILE_FILTER.accept(f)) { 127 try (CachedFile cachedFile = new CachedFile(realPath)) { 128 files.add(cachedFile.getFile()); 129 } 130 } else if (FILE_FILTER.accept(f)) { 110 131 files.add(f); 111 132 } 112 133 progressMonitor.worked(1);
