Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix name validation regex to accept file names beginning with a period #1005

Merged
merged 2 commits into from Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -303,6 +303,12 @@ onlyOnNode20('NodeFileSystemDirectoryHandle', () => {
});
}

test(`accepts file names beginning with a .`, async () => {
G-Rath marked this conversation as resolved.
Show resolved Hide resolved
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