Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: installing local dep from directory that starts with @ #6350

Merged
merged 2 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .changeset/healthy-goats-tell.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
"@pnpm/dependency-path": patch
"@pnpm/lockfile-file": patch
"pnpm": patch
---
Expand Down
6 changes: 6 additions & 0 deletions .changeset/wise-actors-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/lockfile-file": patch
"pnpm": patch
---

Installation should no fail when there is a local dependency that starts in a directory that starts with the `@` char [#6332](https://github.com/pnpm/pnpm/issues/6332).
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function revertFromInlineSpecifiersFormat (lockfile: InlineSpecifiersLock
const PEERS_SUFFIX_REGEX = /(\([^)]+\))+$/

export function convertLockfileV6DepPathToV5DepPath (newDepPath: string) {
if (!newDepPath.includes('@', 2)) return newDepPath
if (!newDepPath.includes('@', 2) || newDepPath.startsWith('file:')) return newDepPath
const index = newDepPath.indexOf('@', newDepPath.indexOf('/@') + 2)
if (newDepPath.includes('(') && index > newDepPath.search(PEERS_SUFFIX_REGEX)) return newDepPath
return `${newDepPath.substring(0, index)}/${newDepPath.substring(index + 1)}`
Expand Down
6 changes: 4 additions & 2 deletions packages/dependency-path/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
return resolutionLocation
}

const PEERS_SUFFIX_REGEX = /(\([^)]+\))+$/

export function tryGetPackageId (registries: Registries, relDepPath: string) {
if (relDepPath[0] !== '/') {
return null
}
const sepIndex = relDepPath.indexOf('(')
if (sepIndex !== -1) {
return resolve(registries, relDepPath.slice(0, sepIndex))
if (sepIndex !== -1 && relDepPath.search(PEERS_SUFFIX_REGEX) !== -1) {

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
return resolve(registries, relDepPath.replace(PEERS_SUFFIX_REGEX, ''))

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of '(()'.
This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
}
const underscoreIndex = relDepPath.indexOf('_', relDepPath.lastIndexOf('/'))
if (underscoreIndex !== -1) {
Expand Down
1 change: 1 addition & 0 deletions packages/dependency-path/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,5 @@ test('depPathToFilename()', () => {
test('tryGetPackageId', () => {
expect(tryGetPackageId({ default: 'https://registry.npmjs.org/' }, '/foo/1.0.0_@types+babel__core@7.1.14')).toEqual('registry.npmjs.org/foo/1.0.0')
expect(tryGetPackageId({ default: 'https://registry.npmjs.org/' }, '/foo/1.0.0(@types/babel__core@7.1.14)')).toEqual('registry.npmjs.org/foo/1.0.0')
expect(tryGetPackageId({ default: 'https://registry.npmjs.org/' }, '/@(-.-)/foo/1.0.0(@types/babel__core@7.1.14)')).toEqual('registry.npmjs.org/@(-.-)/foo/1.0.0')
})