Skip to content

Commit

Permalink
fix: sanitize dir names in the store (#4726)
Browse files Browse the repository at this point in the history
close #4716
  • Loading branch information
zkochan committed May 13, 2022
1 parent fe06f7d commit c576955
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/hot-hairs-thank.md
@@ -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)
2 changes: 1 addition & 1 deletion packages/dependency-path/src/index.ts
Expand Up @@ -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)}`
}
Expand Down
3 changes: 2 additions & 1 deletion packages/dependency-path/test/index.ts
Expand Up @@ -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')
Expand Down

0 comments on commit c576955

Please sign in to comment.