Open cloutiertyler opened 6 years ago
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
I've created https://github.com/skylab-inc/PathToRegex which appears to fix the problem. I just copied the implementation from path-to-regex, so I haven't thought through the logic myself.
By contrast
The Swift version of the regex will match both
which is undesireable.
The JS version will only match