fix: sanitize dir names in the store (#4726)

close #4716
This commit is contained in:
Zoltan Kochan
2022-05-13 13:28:22 +03:00
committed by GitHub
parent fe06f7de4b
commit c576955506
3 changed files with 9 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"dependency-path": patch
"pnpm": patch
---
Sanitize the directory names created inside `node_modules/.pnpm` and inside the global store [#4716](https://github.com/pnpm/pnpm/issues/4716)

View File

@@ -131,7 +131,7 @@ export function parse (dependencyPath: string) {
}
export function depPathToFilename (depPath: string) {
const filename = depPathToFilenameUnescaped(depPath).replace(/\//g, '+')
const filename = depPathToFilenameUnescaped(depPath).replace(/[\\/:*?"<>|]/g, '+')
if (filename.length > 120 || filename !== filename.toLowerCase() && !filename.startsWith('file+')) {
return `${filename.substring(0, 50)}_${createBase32Hash(filename)}`
}

View File

@@ -130,7 +130,8 @@ test('resolve()', () => {
test('depPathToFilename()', () => {
expect(depPathToFilename('/foo/1.0.0')).toBe('foo@1.0.0')
expect(depPathToFilename('/@foo/bar/1.0.0')).toBe('@foo+bar@1.0.0')
expect(depPathToFilename('github.com/something/foo/0000')).toBe('github.com+something+foo@0000')
expect(depPathToFilename('github.com/something/foo/0000?v=1')).toBe('github.com+something+foo@0000+v=1')
expect(depPathToFilename('\\//:*?"<>|')).toBe('++@+++++++')
const filename = depPathToFilename('file:test/foo-1.0.0.tgz_foo@2.0.0')
expect(filename).toBe('file+test+foo-1.0.0.tgz_foo@2.0.0')