diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLCatalogs.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLCatalogs.java index 11feb03c5f..b6aa3ce10c 100644 --- a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLCatalogs.java +++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/ui/preferences/XMLCatalogs.java @@ -13,7 +13,6 @@ import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -152,7 +151,7 @@ private static URI resolveURI(IConfigurationElement element) { ILog.get().warn("A URL object was not found for the given URI " + uri + " from " + contributorName); return null; } - } catch (InvalidRegistryObjectException | URISyntaxException | MalformedURLException e) { + } catch (InvalidRegistryObjectException | URISyntaxException e) { ILog.get().error(e.getMessage(), e); return null; } @@ -199,9 +198,9 @@ private static URI resolveURI(IConfigurationElement element) { * * @param url URL to convert * @return converted URI - * @throws MalformedURLException Error creating a + * @throws URISyntaxException if the URL can't be converted to a URI */ - private static URI convertToURI(URL url) throws URISyntaxException, MalformedURLException { + private static URI convertToURI(URL url) throws URISyntaxException { if ("file".equals(url.getProtocol())) { return new URI(url.getProtocol(), url.getAuthority(), url.getPath(), null, null); } @@ -222,9 +221,10 @@ private static URI convertToURI(URL url) throws URISyntaxException, MalformedURL jarURLString = jarURLString.substring(0, startEntry); } - // convert JAR-URL - URL jarURL = new URL(jarURLString); - URI jarURI = convertToURI(jarURL); + // convert JAR-URL, quoting the characters that are not valid in a URI + URI jarURI = jarURLString.startsWith("file:") + ? new URI("file", null, jarURLString.substring("file:".length()), null) + : new URI(jarURLString); // build URI with valid JAR-URL by replacing the URL of the JAR with the valid // one diff --git a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/SchemaAssociationDialog.java b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/SchemaAssociationDialog.java index aedfee932f..5a78675db7 100644 --- a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/SchemaAssociationDialog.java +++ b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/SchemaAssociationDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020 EclipseSource and others. + * Copyright (c) 2020, 2026 EclipseSource and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -11,8 +11,8 @@ import java.io.File; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import java.util.Arrays; import java.util.Set; @@ -200,10 +200,13 @@ private boolean validateDialog() { } String schemaLocation; + String location = schemaLocationData.getText(); try { - URL locationURL = new URL(schemaLocationData.getText()); - if (locationURL.getProtocol().equals("file")) { - File file = new File(locationURL.getPath()); + if (location.regionMatches(true, 0, "file:", 0, "file:".length())) { + // Browse fills in "file://" followed by the plain absolute path, which may + // contain characters that are not valid in a URI (e.g. spaces), so the path + // is taken as is instead of being parsed as URI. + File file = new File(location.substring("file:".length()).replaceFirst("^//", "")); if (file.exists()) { schemaLocation = "file://" + file.getAbsolutePath(); } else { @@ -211,9 +214,12 @@ private boolean validateDialog() { return updateOkButton(false); } } else { - schemaLocation = locationURL.toURI().toString(); + URI locationURI = new URI(location); + // Check that the URI is absolute and its scheme is supported + locationURI.toURL(); + schemaLocation = locationURI.toString(); } - } catch (MalformedURLException | URISyntaxException | NullPointerException e) { + } catch (MalformedURLException | URISyntaxException | IllegalArgumentException e) { setErrorMessage(SchemaAssociationsMessages.SchemaAssociationDialog_Error_SchemaLocation_invalid); return updateOkButton(false); } diff --git a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/SchemaAssociationRegistry.java b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/SchemaAssociationRegistry.java index d14e54a4e7..c3d931a059 100644 --- a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/SchemaAssociationRegistry.java +++ b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/SchemaAssociationRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 Red Hat Inc. and others. + * Copyright (c) 2021, 2026 Red Hat Inc. and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -10,7 +10,7 @@ package org.eclipse.wildwebdeveloper; import java.io.IOException; -import java.net.URL; +import java.net.URI; import org.eclipse.core.runtime.FileLocator; @@ -20,8 +20,8 @@ private SchemaAssociationRegistry() {} public static String translate(String url) { try { - return FileLocator.toFileURL(new URL(url)).toString(); - } catch (IOException e) { + return FileLocator.toFileURL(URI.create(url).toURL()).toString(); + } catch (IOException | IllegalArgumentException e) { return url; } } diff --git a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/AbstractRunHTMLDebugTab.java b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/AbstractRunHTMLDebugTab.java index 425ef48f0c..c3a29abeec 100644 --- a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/AbstractRunHTMLDebugTab.java +++ b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/AbstractRunHTMLDebugTab.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2023 Red Hat Inc. and others. + * Copyright (c) 2018, 2026 Red Hat Inc. and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -17,7 +17,8 @@ import java.io.File; import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.text.MessageFormat; import org.eclipse.core.resources.IFile; @@ -423,8 +424,8 @@ private void validateProgramPathAndURL() { } else if (urlRadio.getSelection()) { try { - new URL(urlText.getText()); - } catch (MalformedURLException ex) { + new URI(urlText.getText()).toURL(); + } catch (MalformedURLException | URISyntaxException | IllegalArgumentException ex) { errorMessage = MessageFormat.format( Messages.RunProgramTab_error_malformedUR, ex.getMessage()); diff --git a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/eslint/ESLintClientImpl.java b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/eslint/ESLintClientImpl.java index d5e6325d7b..5c6105762b 100644 --- a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/eslint/ESLintClientImpl.java +++ b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/eslint/ESLintClientImpl.java @@ -13,7 +13,7 @@ package org.eclipse.wildwebdeveloper.eslint; import java.io.File; -import java.net.URL; +import java.net.URI; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -118,7 +118,7 @@ public CompletableFuture openDoc(Map data) { Display.getDefault().asyncExec(() -> { IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport(); try { - browserSupport.createBrowser("openDoc").openURL(new URL(data.get("url"))); + browserSupport.createBrowser("openDoc").openURL(URI.create(data.get("url")).toURL()); } catch (Exception e) { ILog.get().error(e.getMessage(), e); }