[ 
https://issues.apache.org/jira/browse/CAMEL-12713?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16571532#comment-16571532
 ] 

ASF GitHub Bot commented on CAMEL-12713:
----------------------------------------

davsclaus closed pull request #2456: CAMEL-12713 - XsltUriResolver fix: 
relative imports can ignore URI scheme 
URL: https://github.com/apache/camel/pull/2456
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 2520d7f1382..7c302d91021 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.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 Source resolve(String href, String base) throws 
TransformerException {
         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 00000000000..6d4df9e5a37
--- /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());
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> relative paths can remove scheme from xslt URI
> ----------------------------------------------
>
>                 Key: CAMEL-12713
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12713
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.22.0
>            Reporter: Peter Van den Bosch
>            Priority: Major
>              Labels: xslt
>             Fix For: 2.21.3, 2.22.1, 2.23.0
>
>
> When using relative paths in an XSLT referenced from another one, the used 
> URI scheme may be ignored.
> e.g. in case of an XSLT specified by URI "classpath:location/master.xsl",  
> that includes another one:  <xsl:include href="../child.xsl"/>
> In this case, the URI of child.xsl is resolved as just "child.xsl" instead of 
> "classpath:child.xsl", omitting the URI scheme.
> The cause is XsltUriResolver, in which FileUtil.compactPath() is used to 
> calculate the relative URI, but this call ignores the colon separator and 
> considers "classpath:location" as a single path part.
> I'm creating a pull request which passes the URI without scheme to 
> FileUtil.compactPath().



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to