Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot 3.2.2 new nested jar mechanism does not resolve resources containing space in the path #39655

Closed
slovi opened this issue Feb 21, 2024 · 1 comment
Labels
status: superseded An issue that has been superseded by another

Comments

@slovi
Copy link

slovi commented Feb 21, 2024

Hi,
after we migrated from Spring Boot 3.1.8 to 3.2.2, our applications installed in path containing empty space suddenly stoped working.

The problem seems to be in new "nested jar" mechanism used to resource locating in the jar/war file.

I tried to prepare simple test which fails in 3.2.2:

    @BeforeAll
    static void setUpClass() {
        Handlers.register();
    }

    @Test
    void testNestedJarPathWithSpaceEncoded() throws Exception {

        var nestedJarUrl = new URL("jar:nested:/C:/Program%20Files/app.jar/!BOOT-INF/classes/!/static/app/nested.jar");
        var nestedJarConnection = nestedJarUrl.openConnection();
        assertThat(nestedJarConnection.getLastModified(), greaterThan(0L));
    }

This works fine in 3.1.8:

    @BeforeAll
    static void setUpClass() {
        JarFile.registerUrlProtocolHandler();
    }

    @Test
    void testNestedJarPathWithSpaceEncoded() throws Exception {

        var jarUrl = new URL("jar:file:/C:/Program%20Files/app.jar/!/BOOT-INF/classes/!/static/app/nested.jar");
        var jarConnection = jarUrl.openConnection();
        assertThat(jarConnection.getLastModified(), greaterThan(0L));
    }

I think that the problem is in implementation of the NestedUrlConnection class:

	private NestedLocation parseNestedLocation(URL url) throws MalformedURLException {
		try {
			return NestedLocation.parse(url.getPath());
		}
		catch (IllegalArgumentException ex) {
			throw new MalformedURLException(ex.getMessage());
		}
	}

Path should be decoded before passing it to NestedLocation.parse method. The URL passed to static method NestedLocation.fromUrl is also decoded before passed to NestedLocation.parse method.

So I would propose this change:

        private NestedLocation parseNestedLocation(URL url) throws MalformedURLException {
		try {
			return NestedLocation.parse(UrlDecoder.decode(url.getPath()));
		}
		catch (IllegalArgumentException ex) {
			throw new MalformedURLException(ex.getMessage());
		}
	}

Will create PR for that If you do not mind.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 21, 2024
slovi pushed a commit to slovi/spring-boot that referenced this issue Feb 21, 2024
URL can contains empty spaced encoded as %20, so it should be decoded
before passing it to NestedLocation. NestedLocation expects file system
path which should not contain URL encoded values.

Closes spring-projectsgh-39655
@philwebb philwebb added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 22, 2024
@philwebb
Copy link
Member

Closing in favor of PR #39675. Thanks @slovi!

@philwebb philwebb closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

3 participants