You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by jg...@apache.org on 2026/05/15 14:26:32 UTC
(xmlgraphics-fop) branch main updated: FOP-2758 Avoid MalformedURLException when using custom URI schemes
This is an automated email from the ASF dual-hosted git repository.
joao12021996 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/xmlgraphics-fop.git
The following commit(s) were added to refs/heads/main by this push:
new 0b9b52aad FOP-2758 Avoid MalformedURLException when using custom URI schemes
0b9b52aad is described below
commit 0b9b52aad5cba89dd74f441804a9ba3a789c6835
Author: Joao Goncalves <an...@gmail.com>
AuthorDate: Wed Mar 25 14:47:44 2026 -0500
FOP-2758 Avoid MalformedURLException when using custom URI schemes
---
.../org/apache/fop/fonts/FontDetectorFactory.java | 21 ++++++--
.../fop/fonts/FontDetectorFactoryTestCase.java | 59 ++++++++++++++++++++++
2 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/fop-core/src/main/java/org/apache/fop/fonts/FontDetectorFactory.java b/fop-core/src/main/java/org/apache/fop/fonts/FontDetectorFactory.java
index 9a0748715..1cdece3f6 100644
--- a/fop-core/src/main/java/org/apache/fop/fonts/FontDetectorFactory.java
+++ b/fop-core/src/main/java/org/apache/fop/fonts/FontDetectorFactory.java
@@ -21,6 +21,7 @@ package org.apache.fop.fonts;
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@@ -91,12 +92,22 @@ public final class FontDetectorFactory {
// is a directory but don't recurse
FontFileFinder fontFileFinder = new FontFileFinder(eventListener);
URI fontBaseURI = fontManager.getResourceResolver().getBaseURI();
- File fontBase = FileUtils.toFile(fontBaseURI.toURL());
- if (fontBase != null) {
- List<URL> fontURLList = fontFileFinder.find(fontBase);
- fontAdder.add(fontURLList, fontInfoList);
+ URL url = null;
+ try {
+ url = fontBaseURI.toURL();
+ } catch (MalformedURLException e) {
+ log.warn("Unable to detect fonts in font base directory, unknown font base URL: "
+ + fontBaseURI, e);
+ }
+
+ if (url != null) {
+ File fontBase = FileUtils.toFile(url);
+ if (fontBase != null) {
+ List<URL> fontURLList = fontFileFinder.find(fontBase);
+ fontAdder.add(fontURLList, fontInfoList);
- //Can only use the font base URL if it's a file URL
+ //Can only use the font base URL if it's a file URL
+ }
}
// native o/s font directory finding
diff --git a/fop-core/src/test/java/org/apache/fop/fonts/FontDetectorFactoryTestCase.java b/fop-core/src/test/java/org/apache/fop/fonts/FontDetectorFactoryTestCase.java
new file mode 100644
index 000000000..3c599c6f6
--- /dev/null
+++ b/fop-core/src/test/java/org/apache/fop/fonts/FontDetectorFactoryTestCase.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fop.fonts;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+
+import org.junit.Test;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.io.InternalResourceResolver;
+
+public class FontDetectorFactoryTestCase {
+
+ @Test
+ public void testDetect() throws FOPException, URISyntaxException {
+ FontDetector factory = FontDetectorFactory.createDefault();
+
+ InternalResourceResolver mockInternalResourceResolver = mock(InternalResourceResolver.class);
+ when(mockInternalResourceResolver.getBaseURI()).thenReturn(new URI("exist://localhost"));
+
+ FontManager mockFontManager = mock(FontManager.class);
+ when(mockFontManager.getResourceResolver()).thenReturn(mockInternalResourceResolver);
+ FontAdder mockFontAdder = mock(FontAdder.class);
+ FontEventListener mockEventListener = mock(FontEventListener.class);
+
+ boolean exceptionThrown = false;
+ try {
+ factory.detect(mockFontManager, mockFontAdder, false, mockEventListener, new ArrayList<>());
+ } catch (Exception e) {
+ if (!(e instanceof MalformedURLException)) {
+ throw e; // Re-throw unexpected exceptions
+ }
+ exceptionThrown = true;
+ }
+
+ assertFalse("If the URL is malformed, we should just log a warning", exceptionThrown);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org