Skip to content

Re-use isValidBasename in file picker#73332

Merged
alexr00 merged 3 commits intomasterfrom
alexr00/isValidBasename
May 16, 2019
Merged

Re-use isValidBasename in file picker#73332
alexr00 merged 3 commits intomasterfrom
alexr00/isValidBasename

Conversation

@alexr00
Copy link
Member

@alexr00 alexr00 commented May 6, 2019

Fixes #72866

@alexr00 alexr00 added this to the May 2019 milestone May 6, 2019
@alexr00 alexr00 requested a review from bpasero May 6, 2019 09:28
@alexr00
Copy link
Member Author

alexr00 commented May 6, 2019

I'm not going to merge this until our May milestone.

export function isValidBasename(name: string | null | undefined): boolean {
export function isValidBasename(name: string | null | undefined, isWindowsOS?: boolean): boolean {
const useWindowsRules = ((isWindowsOS === undefined) ? isWindows : isWindowsOS);
const INVALID_FILE_CHARS = useWindowsRules ? /[\\/:\*\?"<>\|]/g : /[\\/]/g;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexr00 suggest to move this back out of the function and make it 2 variables WINDOWS_INVALID_FILE_CHARS and UNIX_INVALID_FILE_CHARS

const WINDOWS_FORBIDDEN_NAMES = /^(con|prn|aux|clock\$|nul|lpt[0-9]|com[0-9])$/i;
export function isValidBasename(name: string | null | undefined): boolean {
export function isValidBasename(name: string | null | undefined, isWindowsOS?: boolean): boolean {
const useWindowsRules = ((isWindowsOS === undefined) ? isWindows : isWindowsOS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexr00 instead of having a second "isWindows" variable here, why not make the optional parameter isWindowsOS have a default, such as:

export function isValidBasename(name: string | null | undefined, isWindowsOS = isWindows): boolean {

@bpasero bpasero removed their assignment May 6, 2019
@alexr00 alexr00 merged commit b57b987 into master May 16, 2019
@alexr00 alexr00 deleted the alexr00/isValidBasename branch May 16, 2019 18:29
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-use isValidBasename in file picker

2 participants