Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@


import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.internal.InternalPolicy;
import org.eclipse.jface.util.Policy;
Expand Down Expand Up @@ -254,7 +253,7 @@ private static String getFilePath(URL url, boolean logException) {
url = resolvePathVariables(url);
URL locatedURL = FileLocator.toFileURL(url);
return getFilePath(locatedURL);
} catch (IOException | URISyntaxException e) {
} catch (IOException e) {
if (logException) {
Policy.logException(e);
} else if (InternalPolicy.DEBUG_LOG_URL_IMAGE_DESCRIPTOR_MISSING_2x) {
Expand All @@ -267,11 +266,11 @@ private static String getFilePath(URL url, boolean logException) {
}
}

private static String getFilePath(URL url) throws URISyntaxException {
private static String getFilePath(URL url) {
if (FILE_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
Path filePath = Path.of(url.toURI());
if (Files.exists(filePath)) {
return filePath.toString();
File file = IPath.fromOSString(url.getPath()).toFile();
if (file.exists()) {
return file.getPath();
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;

import java.io.File;
import java.io.IOException;
import java.net.URL;

Expand Down Expand Up @@ -154,6 +155,23 @@ private void testImageFileNameProviderGetxName_forFileURL(boolean osgiAvailable)
}
}

@Test
public void testImageFileNameProviderGetxName_forFileURL_WhiteSpace() throws IOException {
File imageFolder = tempFolder.newFolder("folder with spaces");
File imageFile = new File(imageFolder, "image with spaces.png");
imageFile.createNewFile();

// This is an invalid URL because the whitespace characters are not properly encoded
URL imageFileURL = new URL("file", null, imageFile.getPath());
ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageFileURL);

ImageFileNameProvider fileNameProvider = Adapters.adapt(descriptor, ImageFileNameProvider.class);
assertNotNull("URLImageDescriptor does not adapt to ImageFileNameProvider", fileNameProvider);

String imagePath100 = fileNameProvider.getImagePath(100);
assertNotNull("URLImageDescriptor ImageFileNameProvider does not return the 100% path", imagePath100);
}

@Test
public void testAdaptToURL() {
ImageDescriptor descriptor = ImageDescriptor
Expand Down
Loading