fix(fs): permit square brackets [] in file paths (#21625)

Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
This commit is contained in:
Rob Hannay 2023-04-21 16:51:12 +01:00 committed by GitHub
parent d6b5679977
commit b853af2c7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View file

@ -73,6 +73,7 @@ describe('util/fs/util', () => {
${'/foo'} | ${false} ${'/foo'} | ${false}
${'&&'} | ${false} ${'&&'} | ${false}
${';'} | ${true} ${';'} | ${true}
${'./[foo]/bar'} | ${true}
`('isValidPath($value) == $expected', ({ value, expected }) => { `('isValidPath($value) == $expected', ({ value, expected }) => {
expect(isValidPath(value, 'cacheDir')).toBe(expected); expect(isValidPath(value, 'cacheDir')).toBe(expected);
}); });

View file

@ -5,7 +5,7 @@ import { logger } from '../../logger';
// http://www.mtu.edu/umc/services/digital/writing/characters-avoid/ // http://www.mtu.edu/umc/services/digital/writing/characters-avoid/
// We allow spaces, but not newlines // We allow spaces, but not newlines
const restricted = /[[\]#%&<>*?\b\n\r\0!'"|‘“^`]/; const restricted = /[#%&<>*?\b\n\r\0!'"|‘“^`]/;
function assertBaseDir(path: string, baseDir: string): void { function assertBaseDir(path: string, baseDir: string): void {
if (!path.startsWith(baseDir)) { if (!path.startsWith(baseDir)) {