Skip to content

fix: percent-decode the token in priompt:// connection URLs - #36

Merged
sujal-maheshwari2004 merged 1 commit into
priompt:mainfrom
MITU-DK:fix/decode-url-token
Nov 18, 2026
Merged

sujal-maheshwari2004 merged 1 commit into
priompt:mainfrom
MITU-DK:fix/decode-url-token

Conversation

@MITU-DK

@MITU-DK MITU-DK commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Issue

Fixes #27

What changed

parseUrl() now percent-decodes the token from a priompt://<token>@host:port URL, the same way parseNatsUrl() already does.
So priompt://ab%2Bc%3D@localhost:8443 now sends Bearer ab+c= instead of Bearer ab%2Bc%3D, which matches the Go CLI.

I also handled a malformed token like %ZZ. Without this, decodeURIComponent throws URIError: URI malformed and the client crashes with a message that doesn't say what's wrong.
Now it throws a clear error ("the token in the connection URL is not valid percent-encoding"). The error message does not include the token, since it's a secret.

Unencoded tokens, URLs with no token, and plain host values behave the same as before.

How I tested it

Ran npm test: 16 pass, 0 fail.

Added two tests in test/token.test.js:

  • an encoded token in PRIOMPT_URL is decoded: fails before the fix (Bearer ab%2Bc%3D) and passes after.
  • a malformed percent-encoded token in PRIOMPT_URL throws a clear error

I also checked that the url option (not only PRIOMPT_URL) sends the decoded token.

Checklist

  • The issue above is assigned to me.
  • I have at most 2 open pull requests in the priompt organisation.
  • Tests pass locally.
  • If this is a good first issue: this is one of my first open-source contributions.

@sujal-maheshwari2004 sujal-maheshwari2004 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally; tests pass. Thanks!

@sujal-maheshwari2004
sujal-maheshwari2004 merged commit 0e673ce into priompt:main Nov 18, 2026
2 checks passed
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.

Percent-decode the token in priompt:// connection URLs

2 participants