You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by "lprimak (via GitHub)" <gi...@apache.org> on 2026/05/21 09:18:16 UTC

[PR] bugfix(3.x): restore resource loading file:// and relative path funct… [shiro]

lprimak opened a new pull request, #2715:
URL: https://github.com/apache/shiro/pull/2715

   …ionality
   
   <!--
   For Security Vulnerabilities, please email: security@shiro.apache.org
   For more details on how to report a vulnerability see: https://www.apache.org/security/
   -->
   
   Following this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] Make sure there is a [GitHub issue](https://github.com/apache/shiro/issues) filed
          for the change (usually before you start working on it).  Trivial changes like typos do not
          require a GitHub issue.  Your pull request should address just this issue, without pulling in other changes.
    - [ ] Format the pull request title like `[#XXX] - Fixes bug in SessionManager`,
          where you replace `#XXX` with the appropriate GitHub issue. Best practice
          is to use the GitHub issue title in the pull request title and in the first line of the commit message.
    - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [ ] add `fixes #XXX` if merging the PR should close a related issue.
    - [ ] Run `mvn verify` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
    - [ ] Committers: Make sure a milestone is set on the PR
    - [ ] Committers: Use "Squash and Merge" to combine all commits into one when merging a PR when appropriate.
   
   Trivial changes like typos do not require a GitHub issue (javadoc, comments...).
   In this case, just format the pull request title like `[DOC] - Add javadoc in SessionManager`.
   
   If this is your first contribution, you have to read the [Contribution Guidelines](https://github.com/apache/shiro/blob/master/CONTRIBUTING.md)
   
   If your pull request is about ~20 lines of code you don't need to sign an [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf)
   if you are unsure please ask on the developers list.
   
   To make clear that you license your contribution under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
    - [ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
    - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] bugfix(3.x): restore resource loading file:// and relative path funct… [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on code in PR #2715:
URL: https://github.com/apache/shiro/pull/2715#discussion_r3293848654


##########
lang/src/main/java/org/apache/shiro/lang/io/ResourceUtils.java:
##########
@@ -148,8 +148,10 @@ public static URL getURLForPath(String resourcePath) throws IOException {
             url = ClassUtils.getResource(stripPrefix(resourcePath));
         } else if (resourcePath.startsWith(URL_PREFIX)) {
             url = URI.create(stripPrefix(resourcePath)).toURL();
+        } else if (resourcePath.startsWith(FILE_PREFIX)) {
+            url = Paths.get(stripPrefix(resourcePath)).toUri().toURL();
         } else {

Review Comment:
   please suggest a fix



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] bugfix(3.x): restore resource loading file:// and relative path funct… [shiro]

Posted by "steinarb (via GitHub)" <gi...@apache.org>.
steinarb commented on PR #2715:
URL: https://github.com/apache/shiro/pull/2715#issuecomment-4529548886

   LGTM!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] bugfix(3.x): restore resource loading file:// and relative path funct… [shiro]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2715:
URL: https://github.com/apache/shiro/pull/2715#discussion_r3293834061


##########
lang/src/main/java/org/apache/shiro/lang/io/ResourceUtils.java:
##########
@@ -148,8 +148,10 @@ public static URL getURLForPath(String resourcePath) throws IOException {
             url = ClassUtils.getResource(stripPrefix(resourcePath));
         } else if (resourcePath.startsWith(URL_PREFIX)) {
             url = URI.create(stripPrefix(resourcePath)).toURL();
+        } else if (resourcePath.startsWith(FILE_PREFIX)) {
+            url = Paths.get(stripPrefix(resourcePath)).toUri().toURL();
         } else {
-            url = URI.create(resourcePath).toURL();
+            url = Paths.get(resourcePath).toUri().toURL();
         }

Review Comment:
   `getURLForPath` JavaDoc (above this method) still mentions loading unprefixed paths via `URI#create(String)`, but the implementation now resolves them via `Paths.get(...).toUri().toURL()`. Please update the JavaDoc to match the current behavior (file-system `Path` resolution), so callers understand how relative/absolute paths are interpreted.



##########
lang/src/test/java/org/apache/shiro/lang/util/ClassUtilsTest.java:
##########
@@ -84,4 +85,17 @@ void testGetClass() {
         assertThat(ClassUtils.forName(ClassUtilsTest.class.getName())).isEqualTo(ClassUtilsTest.class);
         assertThat(ClassUtils.forName(ClassUtilsTest[].class.getName())).isEqualTo(ClassUtilsTest[].class);
     }
+
+    @Test
+    void inputStream() throws IOException {

Review Comment:
   Test method name `inputStream` is quite generic and doesn’t indicate what behavior is being validated (resource loading for classpath/relative/file-prefixed paths). Renaming it to something more specific (and consistent with the other `test...` methods in this class) would make failures easier to interpret.
   



##########
lang/src/test/java/org/apache/shiro/lang/util/ClassUtilsTest.java:
##########
@@ -84,4 +85,17 @@ void testGetClass() {
         assertThat(ClassUtils.forName(ClassUtilsTest.class.getName())).isEqualTo(ClassUtilsTest.class);
         assertThat(ClassUtils.forName(ClassUtilsTest[].class.getName())).isEqualTo(ClassUtilsTest[].class);
     }
+
+    @Test
+    void inputStream() throws IOException {
+        try (InputStream is = getInputStreamForPath("classpath:org/apache/shiro/lang/util/ClassUtilsTest.class")) {
+            assertThat(is.readAllBytes()).isNotEmpty();
+        }
+        try (InputStream is = getInputStreamForPath("target/test-classes/test-data/file.json")) {
+            assertThat(is.readAllBytes()).isNotEmpty();
+        }
+        try (InputStream is = getInputStreamForPath("file:target/test-classes/test-data/file.json")) {
+            assertThat(is.readAllBytes()).isNotEmpty();
+        }

Review Comment:
   The PR description mentions restoring `file://` loading, but this test only exercises an unprefixed relative path and a `file:`-prefixed relative path. Please add a case that passes an actual file URI string (e.g., the value from `Path#toUri()` which will be `file:/...` or `file:///...`) to ensure the `file://`/URI form is covered.



##########
lang/src/main/java/org/apache/shiro/lang/io/ResourceUtils.java:
##########
@@ -148,8 +148,10 @@ public static URL getURLForPath(String resourcePath) throws IOException {
             url = ClassUtils.getResource(stripPrefix(resourcePath));
         } else if (resourcePath.startsWith(URL_PREFIX)) {
             url = URI.create(stripPrefix(resourcePath)).toURL();
+        } else if (resourcePath.startsWith(FILE_PREFIX)) {
+            url = Paths.get(stripPrefix(resourcePath)).toUri().toURL();
         } else {

Review Comment:
   For `file:`-prefixed values that are actual file URIs (e.g., `file:/...` / `file:///...` with percent-encoding), stripping the scheme and feeding the raw string into `Paths.get(...)` bypasses URI decoding and can point at the wrong on-disk path (e.g., `%20` stays literal). Consider parsing as a `URI` when the value is a URI form and converting via `Paths.get(uri)` (falling back to treating it as a plain path only for `file:`-prefixed relative-path inputs).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] bugfix(3.x): restore resource loading file:// and relative path funct… [shiro]

Posted by "steinarb (via GitHub)" <gi...@apache.org>.
steinarb commented on code in PR #2715:
URL: https://github.com/apache/shiro/pull/2715#discussion_r3295083386


##########
lang/src/test/java/org/apache/shiro/lang/util/ClassUtilsTest.java:
##########
@@ -84,4 +85,17 @@ void testGetClass() {
         assertThat(ClassUtils.forName(ClassUtilsTest.class.getName())).isEqualTo(ClassUtilsTest.class);
         assertThat(ClassUtils.forName(ClassUtilsTest[].class.getName())).isEqualTo(ClassUtilsTest[].class);
     }
+
+    @Test
+    void inputStreamFileLoading() throws IOException {

Review Comment:
   FWIW If a test can throw a checked exception, I usually just go for declaring throwing of the Exception base class. That way I won't get extra clutter if methods needs to throw more checked exception.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] bugfix(3.x): restore resource loading file:// and relative path funct… [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on code in PR #2715:
URL: https://github.com/apache/shiro/pull/2715#discussion_r3295152164


##########
lang/src/test/java/org/apache/shiro/lang/util/ClassUtilsTest.java:
##########
@@ -84,4 +85,17 @@ void testGetClass() {
         assertThat(ClassUtils.forName(ClassUtilsTest.class.getName())).isEqualTo(ClassUtilsTest.class);
         assertThat(ClassUtils.forName(ClassUtilsTest[].class.getName())).isEqualTo(ClassUtilsTest[].class);
     }
+
+    @Test
+    void inputStreamFileLoading() throws IOException {

Review Comment:
   Interesting... I think either is equally valid in this case :)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] bugfix(3.x): restore resource loading file:// and relative path funct… [shiro]

Posted by "steinarb (via GitHub)" <gi...@apache.org>.
steinarb merged PR #2715:
URL: https://github.com/apache/shiro/pull/2715


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] bugfix(3.x): restore resource loading file:// and relative path funct… [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on code in PR #2715:
URL: https://github.com/apache/shiro/pull/2715#discussion_r3293849006


##########
lang/src/test/java/org/apache/shiro/lang/util/ClassUtilsTest.java:
##########
@@ -84,4 +85,17 @@ void testGetClass() {
         assertThat(ClassUtils.forName(ClassUtilsTest.class.getName())).isEqualTo(ClassUtilsTest.class);
         assertThat(ClassUtils.forName(ClassUtilsTest[].class.getName())).isEqualTo(ClassUtilsTest[].class);
     }
+
+    @Test
+    void inputStream() throws IOException {
+        try (InputStream is = getInputStreamForPath("classpath:org/apache/shiro/lang/util/ClassUtilsTest.class")) {
+            assertThat(is.readAllBytes()).isNotEmpty();
+        }
+        try (InputStream is = getInputStreamForPath("target/test-classes/test-data/file.json")) {
+            assertThat(is.readAllBytes()).isNotEmpty();
+        }
+        try (InputStream is = getInputStreamForPath("file:target/test-classes/test-data/file.json")) {
+            assertThat(is.readAllBytes()).isNotEmpty();
+        }

Review Comment:
   suggest a fix



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org