Skip to content

Commit

Permalink
fix: accept file names beginning with a period (#1005)
Browse files Browse the repository at this point in the history
* 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 <Jones258@Gmail.com>
  • Loading branch information
nileflowers and G-Rath committed Feb 21, 2024
1 parent f9b4ef3 commit 3c18dae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/node-to-fsa/util.ts
Expand Up @@ -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);
Expand Down

0 comments on commit 3c18dae

Please sign in to comment.