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 <[email protected]>
  • Loading branch information
nileflowers and G-Rath authored Feb 21, 2024
1 parent f9b4ef3 commit 3c18dae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.