Skip to content

Fix double URL-encoding of paths with spaces in category-p2-metadata#6120

Open
renemuehle wants to merge 1 commit into
eclipse-tycho:mainfrom
renemuehle:fix-category-p2-metadata-spaces
Open

Fix double URL-encoding of paths with spaces in category-p2-metadata#6120
renemuehle wants to merge 1 commit into
eclipse-tycho:mainfrom
renemuehle:fix-category-p2-metadata-spaces

Conversation

@renemuehle

Copy link
Copy Markdown

Problem

tycho-p2-plugin:category-p2-metadata fails when the build/output path contains a space
(or any character requiring percent-encoding), e.g. a Jenkins workspace named My Build:

ProvisionException: Error reading update site file:/.../my%2520site/category.xml
-> "P2 publisher return code was 1"

Root cause

CategoryP2MetadataMojo#addArguments emits the -metadataRepository / -categoryDefinition
arguments via toURI().toURL().toExternalForm() — an encoded URI string (space → %20).
CategoryPublisherApplication / AbstractPublisherApplication then parse them with
org.eclipse.core.runtime.URIUtil.fromString(String), whose javadoc states it is for
unencoded strings and:

This method must not be called with a string that already contains an encoded URI,
since this will result in the URI escape character ('%') being escaped itself.

So %20 is re-encoded to %2520, and the publisher looks for a non-existent directory
literally named my%20site.

Fix

Use URIUtil.toUnencodedString(URI) — the documented counterpart of URIUtil.fromString
so producer and consumer use the matching encoding convention. Verified that the same
fromString logic then yields correct single-encoding on both Windows and Linux.

Reproduction (independent of any wrapper plugin)

  1. Take a p2 metadata repo (content.jar + artifacts.jar) and a category.xml, placed under
    a directory whose absolute path contains a space, e.g. .../my site/repository/.
  2. Run tycho-p2-plugin:category-p2-metadata with target = that repo dir and
    categoryDefinition = that category.xml.
  3. It fails as above; the same inputs under a space-free path succeed.

Affected

Reproduced with 5.0.3; the offending code is unchanged on main.

Related: #5939, #652 (same family of path-encoding issues, different code path).

CategoryP2MetadataMojo passes the metadata repository and category
definition locations as already-encoded URI strings (toURI/toURL/
toExternalForm) to CategoryPublisherApplication, which parses them with
URIUtil.fromString(String). That method is documented for *unencoded*
strings and warns it must not be called with an already-encoded URI, as
the escape character '%' gets escaped itself. The space's %20 thus becomes
%2520 and the publisher fails with "P2 publisher return code was 1":

  ProvisionException: Error reading update site
  file:/.../my%2520site/category.xml

Use URIUtil.toUnencodedString(URI), the documented counterpart of
URIUtil.fromString, so producer and consumer use the matching convention.

Signed-off-by: Rene Muehle <renemuehle@gmail.com>
@laeubi

laeubi commented Jul 16, 2026

Copy link
Copy Markdown
Member

@renemuehle can you provide an integration-test to demonstrate the issue and make sure it does not brake in the future?

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.

2 participants