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

Router path regexp problem #927

Closed
yale8848 opened this issue Mar 13, 2018 · 3 comments
Closed

Router path regexp problem #927

yale8848 opened this issue Mar 13, 2018 · 3 comments

Comments

@yale8848
Copy link
Contributor

app *mvc.Application
app.Router.Get("/total/{year:string regexp(\\d{4})}",...)

I find this regexp doesn't work and i find code below:

core/router/path.go

func cleanPath(s string) string {
	if s == "" || s == "." {
		return "/"
	}

	// remove suffix "/"
	if lidx := len(s) - 1; s[lidx] == '/' {
		s = s[:lidx]
	}

	// prefix with "/"
	s = prefix(s, "/")

	// remove the os specific dir sep
	s = strings.Replace(s, "\\", "/", -1)

	// use std path to clean the path
	s = path.Clean(s)

	return s
}

s = strings.Replace(s, "\\", "/", -1) it will replace the path to /total/{year:string regexp(/d{4})} and so the regexp doesn't work, is this a bug?

@kataras
Copy link
Owner

kataras commented Mar 13, 2018

@yale8848 read this and you will be fine: #918 (comment)

@kataras kataras closed this as completed Mar 13, 2018
kataras added a commit that referenced this issue Mar 13, 2018
@kataras
Copy link
Owner

kataras commented Mar 13, 2018

Although I fixed it @yale8848 , you can use your code above but I recommend using macros, so you can re-use your regex everywhere in your app's routes. Thanks for the report and your interest into Iris, as always :)

@yale8848
Copy link
Contributor Author

Get it.
Thanks very much.
👍

github-actions bot pushed a commit to goproxies/github.com-kataras-iris that referenced this issue Jul 27, 2020
Former-commit-id: 7de62d36b7927d790f5af0c1e64713e0a78d12c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants