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

Difference in behavior from path-to-regex #13

Open
cloutiertyler opened this issue Nov 23, 2017 · 1 comment
Open

Difference in behavior from path-to-regex #13

cloutiertyler opened this issue Nov 23, 2017 · 1 comment

Comments

@cloutiertyler
Copy link

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
Copy link
Author

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.

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

1 participant