[camel] branch master updated: CAMEL-12713 - XsltUriResolver fix: relative paths can remove scheme from XSLT URI (#2456)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated: CAMEL-12713 - XsltUriResolver fix: relative paths can remove scheme from XSLT URI (#2456)

davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 9072148  CAMEL-12713 - XsltUriResolver fix: relative paths can remove scheme from XSLT URI (#2456)
9072148 is described below

commit 9072148a758055ed1eb8bdb6bcd2cee7be778282
Author: Peter Van den Bosch <[hidden email]>
AuthorDate: Tue Aug 7 14:02:35 2018 +0200

    CAMEL-12713 - XsltUriResolver fix: relative paths can remove scheme from XSLT URI (#2456)
---
 .../org/apache/camel/builder/xml/XsltUriResolver.java  |  7 +++++--
 .../apache/camel/builder/xml/XsltUriResolverTest.java  | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java b/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
index 2520d7f..7c302d9 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/xml/XsltUriResolver.java
@@ -27,6 +27,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ResourceHelper;
+import org.apache.camel.util.StringHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -74,14 +75,16 @@ public class XsltUriResolver implements URIResolver {
         LOG.trace("Resolving URI with href: {} and base: {}", href, base);
 
         String scheme = ResourceHelper.getScheme(href);
+
         if (scheme != null) {
             // need to compact paths for file/classpath as it can be relative paths using .. to go backwards
+            String hrefPath = StringHelper.after(href, scheme);
             if ("file:".equals(scheme)) {
                 // compact path use file OS separator
-                href = FileUtil.compactPath(href);
+                href = scheme + FileUtil.compactPath(hrefPath);
             } else if ("classpath:".equals(scheme)) {
                 // for classpath always use /
-                href = FileUtil.compactPath(href, '/');
+                href = scheme + FileUtil.compactPath(hrefPath, '/');
             }
             LOG.debug("Resolving URI from {}: {}", scheme, href);
 
diff --git a/camel-core/src/test/java/org/apache/camel/builder/xml/XsltUriResolverTest.java b/camel-core/src/test/java/org/apache/camel/builder/xml/XsltUriResolverTest.java
new file mode 100644
index 0000000..6d4df9e
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/builder/xml/XsltUriResolverTest.java
@@ -0,0 +1,18 @@
+package org.apache.camel.builder.xml;
+
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+
+import javax.xml.transform.Source;
+
+public class XsltUriResolverTest extends TestCase {
+
+    public void testResolveUri() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        XsltUriResolver xsltUriResolver = new XsltUriResolver(context, "classpath:xslt/staff/staff.xsl");
+        Source source = xsltUriResolver.resolve("../../xslt/common/staff_template.xsl", "classpath:xslt/staff/staff.xsl");
+        assertNotNull(source);
+        assertEquals("classpath:xslt/common/staff_template.xsl", source.getSystemId());
+    }
+}