edgedb-js
edgedb-js copied to clipboard
Fix HTTP client database path encoding
Fixes a bug where the HTTP client fails against databases/branches whose names contain / (such as preview/pr-662 or dev/riley) because the database identifier is interpolated directly into /db/${database}/... URLs without encoding, causing the server to interpret / as path separators and return 404.
Changes
- In
packages/gel/src/utils.ts#getAuthenticatedFetch, percent-encode the database/branch identifier before constructing the/db/...URL:- Build
baseUrlfromprotocolandaddressas before. - Compute
encodedDatabase = encodeURIComponent(database). - Build
databaseUrlusingencodedDatabasefor the/db/${encodedDatabase}/...path segment.
- Build
- Add a regression test to
packages/gel/test/client.test.ts(under the existingbinary-over-httpfeature gate) that:- Stubs
globalThis.fetch. - Calls
getAuthenticatedFetchwithdatabase: "preview/pr-662"and valid connection options. - Invokes the returned
authenticatedFetch. - Asserts that the request URL pathname is
/db/preview%2Fpr-662/. - Restores the original
globalThis.fetch.
- Stubs
Rationale
- Aligns the HTTP client behavior with the CLI/binary clients, which support any valid branch/database name including those containing
/. - Prevents subtle 404s when applications use per-branch names like
dev/<user>orpreview/pr-<number>with the HTTP client. - Does not change the public API surface; only fixes URL construction.
Testing
Locally (against the rileytomasek/gel-js fork):
-
yarn install --frozen-lockfile -
yarn turbo run typecheck --filter=gel(pass) -
yarn turbo run lint --filter=gel(pass) -
yarn turbo run test --filter=gel- Fails in this environment at Jest
globalSetupbecause the Gel/EdgeDB server binary (GEL_SERVER_BIN/edgedb-server) is not available. - In CI or a dev environment where the Gel server binary is configured, the updated test suite should run and cover the new regression test.
- Fails in this environment at Jest
Fixes #1320.
The following commit authors need to sign the Contributor License Agreement: