Skip to content

fix(agents): URL-decode collection/agent name path params (#10443)#10471

Merged
mudler merged 1 commit into
masterfrom
fix/collection-name-url-decode-10443
Jun 24, 2026
Merged

fix(agents): URL-decode collection/agent name path params (#10443)#10471
mudler merged 1 commit into
masterfrom
fix/collection-name-url-decode-10443

Conversation

@localai-bot

Copy link
Copy Markdown
Collaborator

What

Fixes #10443 — uploading a document to a collection whose name contains a colon (e.g. legacy-api-key:LiteraryResearch, the auto-created collection for an imported agent) failed with:

collection not found: legacy-api-key%3ALiteraryResearch

Root cause

Echo routes a request via URL.RawPath whenever the path contains percent-encoded characters (%3A for :), and in that case stores the matched path-param value still escaped. So c.Param("name") returned legacy-api-key%3ALiteraryResearch instead of the real name, and the store lookup 404'd.

This is second-order fallout of #10375 / #10387: once colons became valid in collection/agent names (the legacy-api-key: prefix), the URL-decode gap surfaced on every name-bearing endpoint. The collection entry endpoints already worked around it with url.PathUnescape(c.Param("*")); the :name param did not.

Fix

  • Add a small decodedParam(c, name) helper that url.PathUnescapes the path param (falling back to the raw value on invalid encoding).
  • Wire it into all collection endpoints (agent_collections.go) and the agent :name endpoints (agents.go), which carry the identical legacy-api-key: prefix and would 404 the same way.

Test

Added agent_collections_param_test.go, a regression test that routes a %3A-encoded path through Echo's real router and asserts the handler observes the decoded name. Verified it fails before the fix (returns legacy-api-key%3ALiteraryResearch) and passes after.

Full core/http/endpoints/localai/ suite passes; golangci-lint --new-from-merge-base=master reports 0 issues.

Collection and agent names carry a "legacy-api-key:" prefix, so the ':'
arrives percent-encoded as %3A in the request path. Echo routes such
paths via URL.RawPath and stores the matched path-param value still
escaped, so c.Param("name") returned "legacy-api-key%3ALiteraryResearch"
and the store lookup 404'd ("collection not found").

This was second-order fallout of #10375/#10387: once colons became valid
in names, the URL-decode gap surfaced on every name-bearing endpoint.

Add a decodedParam helper that url.PathUnescape's the param (falling back
to the raw value on invalid encoding) and wire it into all collection
endpoints and the agent :name endpoints, which share the identical
prefix. The entry endpoints already unescaped c.Param("*"); this closes
the same gap for :name.

Fixes #10443

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Assisted-by: Claude:claude-opus-4-8 [Claude Code]
@mudler mudler merged commit e604208 into master Jun 24, 2026
60 checks passed
@mudler mudler deleted the fix/collection-name-url-decode-10443 branch June 24, 2026 07:42
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.

A attempt to upload a document to a collection with a colion in its name (created for an agent) fails

2 participants