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

fix: path parsing issue #371

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

NueloSE
Copy link

@NueloSE NueloSE commented Jan 23, 2025

close #366

@EwenQuim

I introduced a new server property StripTrailingSlash that can be activated by using withStripTrailingSlash

this helps remove trailing slash from defined routes and request

Copy link
Member

@EwenQuim EwenQuim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! 🥳

Add some tests and documentation (/documentation folder) please.

Comment on lines -10 to +13
func NewRoute[T, B any](method, path string, handler any, e *Engine, options ...func(*BaseRoute)) Route[T, B] {
func NewRoute[T, B any](method, path string, handler any, e *Engine, config RouteConfig, options ...func(*BaseRoute)) Route[T, B] {
if config.StripTrailingSlash && len(path) > 1 {
path = strings.TrimRight(path, "/")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change the Route signature, and add it as an option as the other ones

Comment on lines +13 to +16
type RouteConfig struct {
StripTrailingSlash bool
}

Copy link
Member

@EwenQuim EwenQuim Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a Route Option please, cf the BaseRoute struct and the option.go file

Comment on lines +87 to +89
if s.StripTrailingSlash && len(r.URL.Path) > 1 {
r.URL.Path = strings.TrimRight(r.URL.Path, "/")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the length condition useful?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is, to avoid strip a route like '/'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmh good idea! Can you make this comparison more explicit?

Comment on lines +85 to +87

// StripTrailingSlash determines if trailing slashes should be removed from routes and requests
StripTrailingSlash bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just use a route option, you can delete it here

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

Successfully merging this pull request may close these issues.

Path parsing issue
2 participants