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

Piotr Klimczak edited comment on FELIX-6416 at 5/15/21, 10:31 PM:
------------------------------------------------------------------

[~karlpauls] regarding FELIX-6326 I think what is going on is that FS path is 
being used as plain text as URL path and then back again as FS path.
 Reality is that FS paths and URL paths are slightly two different worlds and 
there are different requirements against the two.
 So in theory when we are creating URL path from FS path we should encode it 
and then decode it on the other end.

Please see below very dirty fix for FELIX-6326:
{code:java}
Index: 
framework/src/test/java/org/apache/felix/framework/ResourceLoadingTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git 
a/framework/src/test/java/org/apache/felix/framework/ResourceLoadingTest.java 
b/framework/src/test/java/org/apache/felix/framework/ResourceLoadingTest.java
--- 
a/framework/src/test/java/org/apache/felix/framework/ResourceLoadingTest.java   
    (revision 66f4f0ed0db3ccb9200ba99e72abca31a257bac0)
+++ 
b/framework/src/test/java/org/apache/felix/framework/ResourceLoadingTest.java   
    (date 1621117828716)
@@ -120,13 +120,6 @@
         }
 
         URL url = 
testBundle.adapt(BundleWiring.class).getClassLoader().getResource(name);
-
-        URL testURL = new URL(url.getProtocol() + "://" +  url.getHost() + ":" 
+  url.getPort() + "/" + name);
-
-        try (BufferedReader reader = new BufferedReader(new 
InputStreamReader(testURL.openStream())))
-        {
-            assertEquals("This is a Test", reader.readLine());
-        }
     }
 
     public void testResourceLoadingWithDirectory() throws Exception
Index: 
framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git 
a/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
 
b/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
--- 
a/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
    (revision 66f4f0ed0db3ccb9200ba99e72abca31a257bac0)
+++ 
b/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
    (date 1621117574127)
@@ -22,6 +22,7 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
+import java.net.URLDecoder;
 import java.security.Permission;
 
 import org.apache.felix.framework.util.Util;
@@ -46,7 +47,7 @@
     {
         super(url);
 
-        m_path = url.getPath();
+        m_path = URLDecoder.decode(url.getPath());
 
         // If this is an attempt to create a connection to the root of
         // the bundle, then throw an exception since this isn't possible.
Index: 
framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git 
a/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java 
b/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
--- 
a/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java    
    (revision 66f4f0ed0db3ccb9200ba99e72abca31a257bac0)
+++ 
b/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java    
    (date 1621116948599)
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.net.URLEncoder;
 import java.security.ProtectionDomain;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -674,6 +675,15 @@
         // Add a slash if there is one already, otherwise
         // the is no slash separating the host from the file
         // in the resulting URL.
+        String[] pathSegments = path.split("/");
+        StringBuffer encodedPath = new StringBuffer();
+        for (String pathSegment : pathSegments) {
+            encodedPath.append(URLEncoder.encode(pathSegment));
+            encodedPath.append("/");
+        }
+        path = encodedPath.toString();
+        path = path.substring(0, path.length() - 1);
+
         if (!path.startsWith("/"))
         {
             path = "/" + path;
 {code}


was (Author: nannou9):
[~karlpauls] regarding FELIX-6326 I think what is going on is that FS path is 
being used as plain text as URL path and then back again as FS path.
 Reality is that FS paths and URL paths are slightly two different worlds and 
there are different requirements against the two.
 So in theory when we are creating URL path from FS path we should encode it 
and then decode it on the other end.

> FELIX-6326 breaks JDK9+ URLClassLoader by allowing incorrect URL paths
> ----------------------------------------------------------------------
>
>                 Key: FELIX-6416
>                 URL: https://issues.apache.org/jira/browse/FELIX-6416
>             Project: Felix
>          Issue Type: Bug
>          Components: Framework
>    Affects Versions: framework-6.0.4
>         Environment: MacOS
>            Reporter: Piotr Klimczak
>            Priority: Blocker
>
> '#' sign represents URL fragment and is not valid URL path element.
> As per spec it is not allowed for it to be a part of path and instead must be 
> URL encoded.
> So for example for file in location in UNIX systems: 
> "/Users/piotrklimczak/test#", the valid URL encoding to load it in Java is:
> {code:java}
> new File(new URL("file:///Users/piotrklimczak/test%23").toURI()) {code}
> Works.
> While
> {code:java}
> new File(new URL("file:///Users/piotrklimczak/test#").toURI()) {code}
> Returns java.lang.IllegalArgumentException in Java: URI has a fragment 
> component
> FELIX-6326 effectively allows '#' to be accepted as valid URL path element, 
> which in turn breaks JDK9+ URLClassLoader which is using URL fragment (ref) 
> to deal with multi-release jars.
> This then breaks pax-transx-tm-narayana installation in Karaf 4.3.1 (which 
> uses URLClassLoader).
> In my opinion FELIX-6326 should be reverted and users should be encoding 
> special characters correctly in their resource paths as per above example.
> I've taken a risk to mark it as a blocker as effectively it blocks using 
> Narayana TM, rendering Karaf 4.3.1 not usable for us.
> Feel free to downgrade it if my judgement failed here.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to