From 3c18daeb7ee78813ae66df484070f51f3a16777e Mon Sep 17 00:00:00 2001 From: Mohamed Ibrahim Date: Tue, 20 Feb 2024 20:49:04 -0600 Subject: [PATCH] fix: accept file names beginning with a period (#1005) * fix: fix name validation regex to accept file names beginning with a period * Update src/node-to-fsa/__tests__/NodeFileSystemDirectoryHandle.test.ts --------- Co-authored-by: Gareth Jones --- .../__tests__/NodeFileSystemDirectoryHandle.test.ts | 6 ++++++ src/node-to-fsa/util.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/node-to-fsa/__tests__/NodeFileSystemDirectoryHandle.test.ts b/src/node-to-fsa/__tests__/NodeFileSystemDirectoryHandle.test.ts index d70c2de6..5f392d32 100644 --- a/src/node-to-fsa/__tests__/NodeFileSystemDirectoryHandle.test.ts +++ b/src/node-to-fsa/__tests__/NodeFileSystemDirectoryHandle.test.ts @@ -303,6 +303,12 @@ onlyOnNode20('NodeFileSystemDirectoryHandle', () => { }); } + test('accepts file names beginning with a .', async () => { + const { dir } = setup({ '.hidden': 'contents' }); + const fileHandle = await dir.getFileHandle('.hidden'); + expect(fileHandle).toBeInstanceOf(NodeFileSystemFileHandle); + }); + test('can retrieve a child file', async () => { const { dir } = setup({ file: 'contents', subdir: null }); const subdir = await dir.getFileHandle('file'); diff --git a/src/node-to-fsa/util.ts b/src/node-to-fsa/util.ts index 429b8fde..623d53f9 100644 --- a/src/node-to-fsa/util.ts +++ b/src/node-to-fsa/util.ts @@ -18,7 +18,7 @@ export const basename = (path: string, separator: string) => { return lastSlashIndex === -1 ? path : path.slice(lastSlashIndex + 1); }; -const nameRegex = /^(\.{1,2})|(.*(\/|\\).*)$/; +const nameRegex = /^(\.{1,2})$|^(.*([\/\\]).*)$/; export const assertName = (name: string, method: string, klass: string) => { const isInvalid = !name || nameRegex.test(name);