Skip to content

Do not encode the path again when converting a war: URL to a jar: URL - #1260

Open
arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:war-to-jar-double-encoding
Open

arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:war-to-jar-double-encoding

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

Fixes https://bz.apache.org/bugzilla/show_bug.cgi?id=70360

UriUtil.warToJar() builds the jar: URI with new URI("jar", file, null). The multi-argument URI constructors always quote '%', but the path of a war:file: URL is already percent-encoded, so it is encoded twice: war:file:/some%20dir/app.war*/WEB-INF/lib/a.jar becomes jar:file:/some%2520dir/app.war!/WEB-INF/lib/a.jar.

RFC 3986, section 2.4: "Implementations must not percent-encode or decode the same string more than once". 10.1.x and 9.0.x are not affected, they still use the URL constructor.

The single argument constructor is now used, as buildJarUrl() already does.

Tested on a local Tomcat with unpackWARs="false" and a WAR whose WEB-INF/lib JAR contains a web-fragment.xml, no Spring Boot involved:

appBase before after
.../some dir/apps "Failed to scan JAR", NoSuchFileException: .../some%20dir/apps/app.war, fragment ignored fragment applied, no warning
.../nospace/apps fragment applied fragment applied

The new test in TestUriUtil fails without the change.

UriUtil.warToJar() built the jar: URI with the multi-argument URI
constructor, which quotes '%'. The path of a war:file: URL is already
percent-encoded, so a WAR in a directory with a space produced
jar:file:/some%2520dir/app.war!/... and the JARs in WEB-INF/lib of an
unpacked=false WAR could not be scanned. Web fragments, TLDs and
annotations in those JARs were silently ignored.

Use the single argument constructor, as buildJarUrl() already does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant