fix(db): encode new leaf names in create/rename so spaces are accepted - #820
fix(db): encode new leaf names in create/rename so spaces are accepted#820joewiz wants to merge 2 commits into
Conversation
|
@joewiz could add a test to guard against regressions? |
|
@joewiz could you revisit this change? |
The create and rename handlers took the new collection/resource name raw
from the request body and passed it straight to xmldb:create-collection /
xmldb:rename, while every path elsewhere in the module goes through
db:encode-path. Those functions reject a raw space ("Illegal character in
path", FORG0001), so creating a collection named "My Folder" or renaming
to "report final.xml" failed with HTTP 400.
Encode the leaf name with db:encode-path, like every other path in the
module. Verified against a live instance: create "My Folder" and rename to
"renamed file.xml" now return 200 (stored My%20Folder / renamed%20file.xml,
displayed decoded in the listing). Non-ASCII names were already handled by
the xmldb:* functions; this closes the space case and keeps the leaf
consistent with the module's existing full-encode convention.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Duncan asked for a regression guard on this PR (eXide#820). Before the fix, `db:post` passed the new leaf name to xmldb:create-collection / xmldb:rename un-encoded while every path in the module already went through db:encode-path, so a space came back as 400 "Illegal character in path". Nothing in the suite covered it: dbmanager_spec renames to AéB, and the xmldb:* functions escape non-ASCII internally, so only a space (or another URI-illegal ASCII character) exposes the gap. The new spec covers all three call sites the fix touches — create, the collection branch of rename, and the resource branch of rename — plus a create/delete round trip through the DB manager UI, and asserts the listing shows the decoded name so a space survives storage as %20 and comes back. Verified against eXist-db 7.0.0-SNAPSHOT with existdb-openapi 0.10.0: 3 of the 4 tests fail on develop without this PR's fix (the create assertion reports the exact "Illegal character in path" 400), all 4 pass with it, and the full suite is unaffected. Requires develop's cy.execXQuery support command, hence the merge of develop into this branch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
32939a6 to
436456b
Compare
|
[This response was prompted by Joe, drafted by Claude Code, and reviewed by Joe.] @duncdrum @line-o — regression guard added, and I re-checked the premise of the fix against a current build before doing so. Does eXist-db still need eXide to encode the name?Yes. On today's xmldb:create-collection("/db", "Space Test A")
(: → Invalid value for cast/constructor. failed to convert Space Test A
into an XmldbURI: Illegal character in path at index 5 :)
xmldb:create-collection("/db", xmldb:encode("Space Test B"))
(: → /db/Space%20Test%20B :)So the core behavior this PR works around is unchanged, and the one-line encode is still what makes a space work. It also stays correct if core is later changed under eXist-db/exist#3795: eXide passes the raw name the user typed, so there is nothing to double-encode, and the listing already decodes for display. The regression guardNew spec Measured both ways against eXist-db
One honest caveat: the resource-rename case passes even without the fix, because Worth noting why nothing caught this before: The branch is rebased on current |
|
[This response was prompted by Joe, drafted by Claude Code, and reviewed by Joe.] The failing CI test here is not from this PR. CI installs a pinned #865 fixes CI by deploying the packages the eXist-db image bundles rather than pinned ones. On that stack this PR's suite runs clean: the regression guard added here passes 4 of 4 against eXist-db 7.0.0-SNAPSHOT with existdb-openapi 0.10.0, and fails 3 of 4 without the fix. |
[This PR was co-authored with Claude Code. -Joe]
Problem
Creating a collection or renaming a resource/collection to a name containing a space fails with HTTP 400:
The
createandrenamehandlers inmodules/api/db.xqmtook the new leaf name straight from the request body and passed it un-encoded toxmldb:create-collection/xmldb:rename— while every path elsewhere in the module already goes throughdb:encode-path. Thosexmldb:*functions reject a raw space (FORG0001), so spaces in new names never worked. (Non-ASCII names happened to work because thexmldb:*functions escape those internally.)Fix
Encode the new leaf name with the module's existing
db:encode-pathhelper, exactly like every other path the module handles:create:let $name := db:encode-path($body?name)rename:let $target := db:encode-path($body?target)Verification (live instance)
My FolderMy%20Folder, listed asMy Folderrenamed file.xmlrenamed%20file.xml, listed asrenamed file.xmlThe listing decodes for display as before, so the round-trip (create with a space → shows the space) is clean. This keeps the new leaf consistent with the module's existing full-encode convention; it does not change how any other name is stored.