From 29bd9b7fdde67062a053e9d9b9709184a965e055 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 17 Nov 2020 16:23:46 +0100 Subject: [PATCH] Encode hash symbol in jar file path (for compatibility with JDK 11+) Closes gh-26104 --- .../core/io/support/PathMatchingResourcePatternResolver.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index 9feda4082f..369dbab013 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -432,6 +432,9 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol // Possibly "c:" drive prefix on Windows, to be upper-cased for proper duplicate detection filePath = StringUtils.capitalize(filePath); } + // # can appear in directories/filenames, java.net.URL should not treat it as a fragment + filePath = StringUtils.replace(filePath, "#", "%23"); + // Build URL that points to the root of the jar file UrlResource jarResource = new UrlResource(ResourceUtils.JAR_URL_PREFIX + ResourceUtils.FILE_URL_PREFIX + filePath + ResourceUtils.JAR_URL_SEPARATOR); // Potentially overlapping with URLClassLoader.getURLs() result above!