Skip to content

Commit 3ca52e4

Browse files
committed
Use URI to get decoded patch before extracting module name
1 parent b8b2313 commit 3ca52e4

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/main/java/de/thetaphi/forbiddenapis/AsmUtils.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
import java.net.URISyntaxException;
1920
import java.net.URL;
2021
import java.util.Locale;
2122
import java.util.regex.Pattern;
@@ -129,16 +130,21 @@ public static String getModuleName(URL jrtUrl) {
129130
if (!"jrt".equalsIgnoreCase(jrtUrl.getProtocol())) {
130131
return null;
131132
}
132-
String mod = jrtUrl.getPath();
133-
if (mod != null && mod.length() >= 1) {
134-
mod = mod.substring(1);
135-
int p = mod.indexOf('/');
136-
if (p >= 0) {
137-
mod = mod.substring(0, p);
133+
try {
134+
// use URI class to also decode path and remove escapes:
135+
String mod = jrtUrl.toURI().getPath();
136+
if (mod != null && mod.length() >= 1) {
137+
mod = mod.substring(1);
138+
int p = mod.indexOf('/');
139+
if (p >= 0) {
140+
mod = mod.substring(0, p);
141+
}
142+
return mod.isEmpty() ? null : mod;
138143
}
139-
return mod.isEmpty() ? null : mod;
144+
return null;
145+
} catch (URISyntaxException use) {
146+
return null;
140147
}
141-
return null;
142148
}
143149

144150
}

0 commit comments

Comments
 (0)