edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

Fix HTTP client database path encoding

Open rileytomasek opened this issue 2 months ago • 1 comments

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 baseUrl from protocol and address as before.
    • Compute encodedDatabase = encodeURIComponent(database).
    • Build databaseUrl using encodedDatabase for the /db/${encodedDatabase}/... path segment.
  • Add a regression test to packages/gel/test/client.test.ts (under the existing binary-over-http feature gate) that:
    • Stubs globalThis.fetch.
    • Calls getAuthenticatedFetch with database: "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.

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> or preview/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 globalSetup because 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.

Fixes #1320.

rileytomasek avatar Nov 08 '25 16:11 rileytomasek

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:
CLA not signed

gel-data-cla[bot] avatar Nov 08 '25 16:11 gel-data-cla[bot]