Skip to content

Percent encode artifact names in fetch-content#927

Open
Eijebong wants to merge 1 commit intotaskcluster:mainfrom
Eijebong:percent-encode-fetch-content
Open

Percent encode artifact names in fetch-content#927
Eijebong wants to merge 1 commit intotaskcluster:mainfrom
Eijebong:percent-encode-fetch-content

Conversation

@Eijebong
Copy link
Copy Markdown
Contributor

@Eijebong Eijebong commented Apr 2, 2026

Previously, trying to use fetch-content for an artifact that had a space in it would result in errors like Download failed: URL can't contain control characters. '[...]' (found at least ' ')

This commit changes fetch-content so we encode the artifact name when building the download URL instead of putting it verbatim in the URL. Because we're later reusing the URL to get the base name to know which file to write, we now decode the basename so the resulting file doesn't contain percent encoded characters.

Before:

$ export MOZ_FETCHES='[{"task":"FNpL6lwoTVyuWE3wgNeuUw","artifact":"public/Twilight Princess-0.2.3.apworld","extract":false}]'
$ uv run python3 src/taskgraph/run-task/fetch-content task-artifacts -d /tmp/fetch-test
attempt 1/5
Downloading https://taskcluster.bananium.fr/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight Princess-0.3.0.apworld to /tmp/fetch-test/Twilight Princess-0.3.0.apworld
Downloading https://taskcluster.bananium.fr/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight Princess-0.3.0.apworld
Download failed: URL can't contain control characters. '/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight Princess-0.3.0.apworld' (found at least ' ')
sleeping for 60.00s (attempt 1/5)

After:

$ export MOZ_FETCHES='[{"task":"FNpL6lwoTVyuWE3wgNeuUw","artifact":"public/Twilight Princess-0.2.3.apworld","extract":false}]'
$ uv run python3 src/taskgraph/run-task/fetch-content task-artifacts -d /tmp/fetch-test
attempt 1/5
Downloading https://taskcluster.bananium.fr/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight%20Princess-0.3.0.apworld to /tmp/fetch-test/Twilight Princess-0.3.0.apworld
Downloading https://taskcluster.bananium.fr/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight%20Princess-0.3.0.apworld
https://taskcluster.bananium.fr/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight%20Princess-0.3.0.apworld resolved to 155321 bytes with sha256 77c8ccca3da7b040b94a7c8b4c68dc5234556dbc1c5b51f65afc19655f6d00ab in 0.486s
PERFHERDER_DATA: {"framework": {"name": "build_metrics"}, "suites": [{"name": "fetch_content", "value": 0.4895111569785513, "lowerIsBetter": true, "shouldAlert": false, "subtests": []}]}

As another workaround, users could percent encode the artifact name in the fetch config (i.e: MOZ_FETCHES='[{"task":"FNpL6lwoTVyuWE3wgNeuUw","artifact":"public/Twilight%20Princess-0.2.3.apworld","extract":false}]') but that would result with the filename on disk still having the percent encoded characters in it and be confusing because the artifact in the config wouldn't match what the task actually has.

@Eijebong Eijebong requested a review from a team as a code owner April 2, 2026 20:05
@Eijebong Eijebong requested a review from ahal April 2, 2026 20:05
Previously, trying to use fetch-content for an artifact that had a space
in it would result in errors like `Download failed: URL can't contain
control characters. '[...]' (found at least ' ')`

This commit changes fetch-content so we encode the artifact name when
building the download URL instead of putting it verbatim in the URL.
Because we're later reusing the URL to get the base name to know which
file to write, we now decode the basename so the resulting file doesn't
contain percent encoded characters.

Before:

```
$ export MOZ_FETCHES='[{"task":"FNpL6lwoTVyuWE3wgNeuUw","artifact":"public/Twilight Princess-0.2.3.apworld","extract":false}]'
$ uv run python3 src/taskgraph/run-task/fetch-content task-artifacts -d /tmp/fetch-test
attempt 1/5
Downloading https://taskcluster.bananium.fr/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight Princess-0.3.0.apworld to /tmp/fetch-test/Twilight Princess-0.3.0.apworld
Downloading https://taskcluster.bananium.fr/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight Princess-0.3.0.apworld
Download failed: URL can't contain control characters. '/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight Princess-0.3.0.apworld' (found at least ' ')
sleeping for 60.00s (attempt 1/5)
```

After:

```
$ export MOZ_FETCHES='[{"task":"FNpL6lwoTVyuWE3wgNeuUw","artifact":"public/Twilight Princess-0.2.3.apworld","extract":false}]'
$ uv run python3 src/taskgraph/run-task/fetch-content task-artifacts -d /tmp/fetch-test
attempt 1/5
Downloading https://taskcluster.bananium.fr/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight%20Princess-0.3.0.apworld to /tmp/fetch-test/Twilight Princess-0.3.0.apworld
Downloading https://taskcluster.bananium.fr/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight%20Princess-0.3.0.apworld
https://taskcluster.bananium.fr/api/queue/v1/task/DBFKDCtCSi6gg35xPqZHOA/artifacts/public/Twilight%20Princess-0.3.0.apworld resolved to 155321 bytes with sha256 77c8ccca3da7b040b94a7c8b4c68dc5234556dbc1c5b51f65afc19655f6d00ab in 0.486s
PERFHERDER_DATA: {"framework": {"name": "build_metrics"}, "suites": [{"name": "fetch_content", "value": 0.4895111569785513, "lowerIsBetter": true, "shouldAlert": false, "subtests": []}]}
```

As another workaround, users could percent encode the artifact name in
the fetch config but that would result with the filename on disk still
having the percent encoded characters in it and be confusing because the
artifact in the config wouldn't match what the task actually has.

i.e: MOZ_FETCHES='[{"task":"FNpL6lwoTVyuWE3wgNeuUw","artifact":"public/Twilight%20Princess-0.2.3.apworld","extract":false}]'
@Eijebong Eijebong force-pushed the percent-encode-fetch-content branch from 593e099 to 711493e Compare April 2, 2026 20:25
@jcristau
Copy link
Copy Markdown
Contributor

jcristau commented Apr 3, 2026

Isn't this backwards-incompatible, i.e. MOZ_FETCHES='[{"task":"FNpL6lwoTVyuWE3wgNeuUw","artifact":"public/Twilight%20Princess-0.2.3.apworld","extract":false}]' would work before this change, but now the %20 will be turned into %2520 in the url?

@Eijebong Eijebong added the BREAKING CHANGE Backwards incompatible request that will require major version bump label Apr 3, 2026
@Eijebong
Copy link
Copy Markdown
Contributor Author

Eijebong commented Apr 3, 2026

True. Slapped a breaking change label on this. I don't expect anyone to run into this because I would hope that if someone had seen this before they'd had opened an issue but it is a breaking change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BREAKING CHANGE Backwards incompatible request that will require major version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants