Files
pnpm/__patches__/normalize-registry-url@2.0.1.patch
T
Zoltan Kochan 1166108f79 fix(auth): normalize subpath registry URLs with a trailing slash (#13137)
pnpm login, pnpm adduser, and pnpm logout dropped the last path segment
of a registry hosted under a URL subpath when the configured URL had no
trailing slash: normalize-registry-url 2.0.1 returns URLs that already
contain a path unchanged instead of appending the slash, and the WHATWG
relative resolution used to build the -/v1/login, couchdb-user, and
token-revocation endpoints then resolves against the truncated parent
path. The auth token was likewise stored under a truncated key.
Registries at a domain root were unaffected, and so were subpath URLs
written with a trailing slash.

Fix the package once for every consumer (config reader, login, logout,
publish registry keys) with a patchedDependencies patch that always
appends the trailing slash, matching the Rust CLI, whose normalization
was already correct. The lockfile diff is limited to the patch hashes;
the unrelated peer-context re-resolution a full install wanted to make
was reverted deliberately.

The config-reader test expectations that encoded the old truncating
behavior are updated to expect the trailing slash. The Rust side gains
the mirrored subpath-without-trailing-slash tests for web login, classic
login, and logout; its behavior is unchanged.
2026-07-19 10:39:46 +02:00

16 lines
549 B
Diff

diff --git a/index.js b/index.js
index e03373cdeaff3d2d09f7dcf48beab0c5b7e221ac..7ce6d0616bf40aea1d8b9e4ec387bcff6e91281a 100644
--- a/index.js
+++ b/index.js
@@ -8,9 +8,6 @@ module.exports = function (registry) {
// Remove default ports (80 for HTTP, 443 for HTTPS) to ensure consistency
registry = new URL(registry).toString()
} catch {}
- if (
- registry.endsWith('/') ||
- registry.indexOf('/', registry.indexOf('//') + 2) != -1
- ) return registry
+ if (registry.endsWith('/')) return registry
return `${registry}/`
}