Skip to content

fix(node-api): decode percent-encoded path before process.dlopen#49

Open
NathanWalker wants to merge 1 commit into
mainfrom
fix/node-api-dlopen-percent-encoded-path
Open

fix(node-api): decode percent-encoded path before process.dlopen#49
NathanWalker wants to merge 1 commit into
mainfrom
fix/node-api-dlopen-percent-encoded-path

Conversation

@NathanWalker

Copy link
Copy Markdown
Contributor

URL.pathname is percent-encoded, but process.dlopen expects a filesystem path. Any space in the package's path therefore reaches dlopen as "%20" and the addon fails to load:

TypeError: dlopen(/Applications/My%20App.app/.../NativeScript, 0x0001):
  tried: '.../My%20App.app/...' (no such file)

This breaks every packaged app whose path contains a space — for example an .app installed to /Applications with a display name like "My App.app". It goes unnoticed in development because the package normally resolves from a node_modules path with no spaces, where decoding is a no-op; only a distributed bundle exercises the failing path.

Wrap the resolved pathname in decodeURIComponent() at all three dlopen sites:

  • packages/macos-node-api/index.mjs
  • packages/macos-node-api/index.cjs
  • packages/ios-node-api/index.js

Verified on macOS by copying packages/macos-node-api together with its built NativeScript.framework into a directory whose name contains a space, then importing it under Deno:

  • before: dlopen fails with the %20 path shown above
  • after: the addon loads and init() runs

Note: paths containing "#" or "?" are still mishandled, because the base URL is built by string concatenation and those characters are parsed as fragment/query delimiters. Spaces are by far the common case; a complete fix would resolve the addon path without going through URL at all.

`URL.pathname` is percent-encoded, but `process.dlopen` expects a filesystem
path. Any space in the package's path therefore reaches dlopen as "%20" and the
addon fails to load:

    TypeError: dlopen(/Applications/My%20App.app/.../NativeScript, 0x0001):
      tried: '.../My%20App.app/...' (no such file)

This breaks every packaged app whose path contains a space — for example an
.app installed to /Applications with a display name like "My App.app". It goes
unnoticed in development because the package normally resolves from a
node_modules path with no spaces, where decoding is a no-op; only a distributed
bundle exercises the failing path.

Wrap the resolved pathname in decodeURIComponent() at all three dlopen sites:

  - packages/macos-node-api/index.mjs
  - packages/macos-node-api/index.cjs
  - packages/ios-node-api/index.js

Verified on macOS by copying packages/macos-node-api together with its built
NativeScript.framework into a directory whose name contains a space, then
importing it under Deno:

  - before: dlopen fails with the %20 path shown above
  - after:  the addon loads and init() runs

Note: paths containing "#" or "?" are still mishandled, because the base URL is
built by string concatenation and those characters are parsed as fragment/query
delimiters. Spaces are by far the common case; a complete fix would resolve the
addon path without going through URL at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cafc7202-0532-4fc8-88ca-0cc6dda83da7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/node-api-dlopen-percent-encoded-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant