Percent-decode URL paths before filesystem use in any::connect() by adlk · Pull Request #7080 · surrealdb/surrealdb · GitHub
Skip to content

Percent-decode URL paths before filesystem use in any::connect()#7080

Open
adlk wants to merge 2 commits intosurrealdb:mainfrom
adlk:fix/percent-decode-paths
Open

Percent-decode URL paths before filesystem use in any::connect()#7080
adlk wants to merge 2 commits intosurrealdb:mainfrom
adlk:fix/percent-decode-paths

Conversation

@adlk
Copy link
Copy Markdown

@adlk adlk commented Mar 12, 2026

What is the motivation?

any::connect() passes percent-encoded paths straight to the filesystem without decoding them. For example, connecting with surrealkv:///tmp/surrealdb%20path%20test/db creates a directory literally named surrealdb%20path%20test instead of surrealdb path test. This makes it impossible to use paths with spaces (or other special characters) through the any::connect() API, even though the typed engine API (Surreal::new::<SurrealKv>()) handles them correctly.

The same issue exists in surrealdb-core's Datastore::new(), which affects the Node.js embedded engine (@surrealdb/node) — the path extracted after splitting the scheme is never percent-decoded before being passed to the storage engine.

What does this change do?

Two targeted fixes that cover both the Rust SDK and the core datastore paths:

  1. surrealdb SDK crate (surrealdb/src/opt/endpoint/mod.rs): Added percent_decode_str() in path_to_string() so URL-encoded characters are decoded before the path is used on the filesystem. This is the single function all local engine endpoints (SurrealKV, RocksDB, mem with persistence) pass through, so the fix covers all of them.

  2. surrealdb-core crate (surrealdb/core/src/kvs/ds.rs): Added percent_decode_str() in CommunityComposer::new_transaction_builder() right after the scheme/path split. This fixes the same bug for consumers that call Datastore::new() directly (e.g. the Node.js embedded engine).

Supporting changes:

  • Added percent-encoding as a workspace dependency (already in the dep tree via url)
  • Added percent-encoding to both surrealdb and surrealdb-core crate dependencies

What is your testing strategy?

  • Added a unit test test_path_to_string_percent_decoding in surrealdb/src/opt/endpoint/mod.rs that verifies %20 decodes to spaces, %23 decodes to #, and plain paths pass through unchanged. All existing and new tests pass via cargo test -p surrealdb --lib opt::endpoint::tests.
  • Verified end-to-end using the reproduction repo from the issue (https://github.com/adlk/surrealdb-path-test) pointed at this branch. All three scenarios (space in URL, typed engine control, pre-encoded %20) correctly create directories with literal spaces.
  • Built a custom @surrealdb/node native addon against this branch and confirmed it resolves the issue for the Node.js embedded engine as well.

Is this related to any issues?

Fixes #6911

Does this change need documentation?

  • No documentation needed

Does this change make any alterations to environment variables or CLI commands?

  • No changes made to env vars

Have you read the Contributing Guidelines?

@adlk adlk requested a review from a team as a code owner March 12, 2026 08:17
@github-actions github-actions Bot added the community PRs from the community. This label is used to ensure all community PRs get reviewed. label Mar 12, 2026
@adlk adlk requested a review from a team as a code owner March 12, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community PRs from the community. This label is used to ensure all community PRs get reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

any::connect() passes percent-encoded paths to filesystem without decoding

1 participant