Skip to content

Difference in behavior from path-to-regex #13

@cloutiertyler

Description

@cloutiertyler
let regex = try! Regex(path: "/v1.0/login", pathOptions: [])
print(regex.pattern) 
// Outputs:
// ^\/v1\.0\/login(?:\/(?=$))? 

By contrast

var regex = pathToRegexp("/v1.0/login", [], {end: false})
console.log(regex)
// Outputs:
// ^\/v1\.0\/login\/?(?=\/|$)

The Swift version of the regex will match both

/v1.0/login
/v1.0/login2

which is undesireable.

The JS version will only match

/v1.0/login

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions