Skip to content

Resources containing spaces cannot be read from executable jars after #52246 - #52280

Merged
philwebb merged 2 commits into
spring-projects:mainfrom
challa:gh-url-encoder-single-byte
Oct 17, 2026
Merged

philwebb merged 2 commits into
spring-projects:mainfrom
challa:gh-url-encoder-single-byte

Conversation

@challa

@challa challa commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Since #52246, JarUrlClassLoader creates the URLs of resources in nested jars using the new UrlEncoder (added in 059525f). UrlEncoder encodes every character that needs encoding as a two or three byte UTF-8 sequence, so a character below 0x80 is written as an invalid overlong sequence. For example, a space becomes %c0%a0, which UrlDecoder decodes to replacement characters.

As a result, when all class path URLs are nested jar URLs, which is the standard executable jar layout, a resource whose name contains a space (or ", #, %, <, >, ?, [, \, ], ^, `, {, | or }) can no longer be read. For a nested jar containing dir with space/a#b.txt, getResource("dir with space/a#b.txt") returns a URL but opening it fails:

java.io.FileNotFoundException: JAR entry dir��with��space/a��b.txt not found in ...

The resource is read as expected with 4.1.x.

This change encodes characters below 0x80 as a single byte. The new tests in UrlEncoderTests and JarUrlClassLoaderTests fail without it.

Resources with supplementary characters, such as emoji, in their names didn't work with 4.1.x either and still don't, as surrogate pairs aren't combined into a single code point. I've left that out of this change to keep it focused on the regression.

I used an AI coding assistant for parts of the analysis; I reviewed and verified the change and tests myself.

challa added a commit to challa/spring-boot that referenced this pull request Oct 17, 2026
UrlEncoder encoded every character that needs encoding as a two or
three byte UTF-8 sequence. A character below 0x80, such as a space,
was therefore written as an invalid overlong sequence, for example
%c0%a0, that UrlDecoder could not decode back to the character. As
JarUrlClassLoader uses UrlEncoder to create resource URLs for nested
jars, a resource whose name contains such a character could no longer
be read from an executable jar.

This commit encodes characters below 0x80 as a single byte.

See spring-projectsgh-52280

Signed-off-by: Challa Srinivasa Reddy <challa.srinivasareddy@gmail.com>
@challa
challa force-pushed the gh-url-encoder-single-byte branch from 0565476 to e7c849f Compare October 17, 2026 14:10
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Oct 17, 2026
@philwebb philwebb added the type: regression A regression from a previous release label Oct 17, 2026
@philwebb philwebb self-assigned this Oct 17, 2026
@philwebb philwebb added type: blocker An issue that is blocking us from releasing and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Oct 17, 2026
@philwebb philwebb added this to the 4.2.0-RC1 milestone Oct 17, 2026
@philwebb

Copy link
Copy Markdown
Member

Thank you so much @challa! You've absolutely saved the RC1 we are about to release!

challa and others added 2 commits October 17, 2026 14:09
Fix `UrlEncoder` for characters below 0x80, such as a space. Prior
to this commit, the encoder incorrectly skipped single byte chars
that required encoding.

See spring-projectsgh-52280

Signed-off-by: Challa Srinivasa Reddy <challa.srinivasareddy@gmail.com>
@philwebb
philwebb force-pushed the gh-url-encoder-single-byte branch from e7c849f to dc53a64 Compare October 17, 2026 21:10
@philwebb
philwebb merged commit 1b2d2fc into spring-projects:main Oct 17, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: blocker An issue that is blocking us from releasing type: regression A regression from a previous release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants