crossroadlabs / PathToRegex

A Swift library translating paths with wildcards into regular expressions
GNU General Public License v3.0
7 stars 7 forks source link

Difference in behavior from path-to-regex #13

Open cloutiertyler opened 6 years ago

cloutiertyler commented 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
cloutiertyler commented 6 years ago

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.