Author: ssteiner
Date: Tue Oct 12 14:10:49 2021
New Revision: 1894165

URL: http://svn.apache.org/viewvc?rev=1894165&view=rev
Log:
FOP-2973: Cannot use custom schemes starting with "data" in resource resolver
Thanks to J Frank

Modified:
    
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/apps/io/InternalResourceResolver.java
    
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java

Modified: 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/apps/io/InternalResourceResolver.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/apps/io/InternalResourceResolver.java?rev=1894165&r1=1894164&r2=1894165&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/apps/io/InternalResourceResolver.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/apps/io/InternalResourceResolver.java
 Tue Oct 12 14:10:49 2021
@@ -86,7 +86,7 @@ public class InternalResourceResolver {
      * @throws IOException if an I/O error occurred
      */
     public Resource getResource(URI uri) throws IOException {
-        if (uri.getScheme() != null && uri.getScheme().startsWith("data")) {
+        if (uri.getScheme() != null && uri.getScheme().equals("data")) {
             return new Resource(resolveDataURI(uri.toASCIIString()));
         }
         return resourceResolver.getResource(resolveFromBase(uri));

Modified: 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java?rev=1894165&r1=1894164&r2=1894165&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java
 (original)
+++ 
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/apps/io/URIResolverWrapperTestCase.java
 Tue Oct 12 14:10:49 2021
@@ -19,6 +19,8 @@
 package org.apache.fop.apps.io;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Arrays;
@@ -35,7 +37,11 @@ import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
+import org.apache.commons.io.IOUtils;
+
 import org.apache.xmlgraphics.io.ResourceResolver;
+import org.apache.xmlgraphics.util.WriterOutputStream;
+import org.apache.xmlgraphics.util.io.Base64EncodeStream;
 
 public class URIResolverWrapperTestCase {
 
@@ -60,7 +66,8 @@ public class URIResolverWrapperTestCase
 
     @Test
     public void testResolveIn() throws Exception {
-        String[] uris = new String[] {".", "resource", "path/to/resource"};
+        String[] uris = new String[]{".", "resource", "path/to/resource",
+                
"datafoo:application/octet-stream;interpreter=fop;base64,AAECAwQF"};
         for (String base : BASE_URIS) {
             setBase(base);
             for (String uriStr : uris) {
@@ -72,6 +79,20 @@ public class URIResolverWrapperTestCase
     }
 
     @Test
+    public void testGetResourceForURIStartingWithData() throws Exception {
+        String uriStr = 
"data:application/octet-stream;interpreter=fop;base64,AAECAwQF";
+        ResourceResolver resolver = mock(ResourceResolver.class);
+        InternalResourceResolver sut = new InternalResourceResolver(base, 
resolver);
+        URI uri = new URI(uriStr);
+        InputStream actual = sut.getResource(uri);
+        StringWriter stringWriter = new StringWriter();
+        Base64EncodeStream out = new Base64EncodeStream(
+                new WriterOutputStream(stringWriter, "US-ASCII"), false);
+        IOUtils.copy(actual, out);
+        assertEquals("AAECAwQF", stringWriter.toString());
+    }
+
+    @Test
     public void testResolveInBadUri() throws Exception {
         String[] uris = new String[] {"path\\to\\resource", "bad resource 
name"};
         for (String base : BASE_URIS) {



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org

Reply via email to