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

Problem with parentheses #6

Open
speker2010 opened this issue Mar 24, 2022 · 2 comments
Open

Problem with parentheses #6

speker2010 opened this issue Mar 24, 2022 · 2 comments

Comments

@speker2010
Copy link

There is should be something like this 'images/my-photo(1).jpg', isn't it? https://github.com/jonschlinkert/is-valid-path/blob/master/test.js#L15-L20

I think it's correct filename

@air2
Copy link

air2 commented Apr 4, 2022

I have the same issue. Parentheses are incorrectly considered invalid.

@air2
Copy link

air2 commented Apr 5, 2022

I quickly wrote this function to test paths. I guess it can be better, but it is just a quick fix to solve this problem in our code

export function isValidPath(pathName: string) {
    try {
        const resolvedPath = resolve(pathName)
        if (resolvedPath) {
            if (process.platform === 'win32') {
                if (pathName.length > 4 && pathName[2] === '?' && pathName[0] === '\\' && pathName[1] === '\\' && pathName[3] === '\\') { pathName = pathName.substring(4) }
                if (pathName.length > 2 && pathName[1] === ':' && pathName[2] === '\\') { pathName = pathName.substring(2) }
                return !/[<>:"|?*]/.test(pathName)
            }
            return true
        }
    }
    catch(_e: unknown) {
    }
    return false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants