Skip to content

Path slash differences with Windows and Linux #896

@mcottontensor

Description

@mcottontensor

On trying to get started with express-openapi on a Windows development environment, I got a nasty error about Unmatched ')' in a regular expression. Trying to hunt it down led me to fs-routes where files are being resolved.
Using path.resolve on Windows resolves paths with back slashes and on Linux, forward slashes. Code further down the line seems to assume all path separators are forward slashes. This means that some of the generated routes will become invalid and lead to broken code.
I changed the end of the fsRoutes() function to look like

.map(function (file) { return ({
            path: path.resolve(dir, file).replace(/\\/g, '/'),
            route: '/' + file.replace(options.indexFileRegExp, '').replace(/\\/g, '/')
        }); });

as a test and that fixed the issues I was having.

Is there a better way of handling this? I was a little surprised no one else had stumbled across this error so it leads me to believe I'm doing something wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions