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

undocumented behaviour: HeadersRegexp wraps regexp in wildcard by default #124

Closed
bluehallu opened this issue Sep 8, 2015 · 12 comments
Closed

Comments

@bluehallu
Copy link

bluehallu commented Sep 8, 2015

Not sure if this is intended, but using this regexp abc, actually means you're using .*abc.*. I don't think this is appropriate since it doesn't let me specify I want certain order on the Accept header, for instance.

@bluehallu bluehallu changed the title weird undocumenteded behaviour: HeadersRegexp wraps regexp in wildcard by default undocumenteded behaviour: HeadersRegexp wraps regexp in wildcard by default Sep 8, 2015
@elithrar elithrar changed the title undocumenteded behaviour: HeadersRegexp wraps regexp in wildcard by default undocumented behaviour: HeadersRegexp wraps regexp in wildcard by default Sep 10, 2015
@themihai
Copy link

themihai commented Jun 9, 2016

I find this kind of behaviour/regex flavour quite disturbing especially because it's not documented. For example using signin.api{_:(^$|^\.sandbox$)}.example.co.uk with the standard regexp package matches sigin.api.example.co.uk and signin.api.sandbox.example.co.uk but on route.Host that doesn't happen.

@elithrar
Copy link
Contributor

@themihai If you can submit a PR documenting this it'd be hugely appreciated. I don't think we can (safely) change this behaviour given applications depending on it in the wild.

@bluehallu
Copy link
Author

@elithrar The problem is that it's not just undocumented behaviour, it's actually preventing you from supplying your own raw regex!

@elithrar
Copy link
Contributor

@bluehallu I get that: but changing it would impact other applications out there. I'm not defending code I wrote (I didn't write it), I'm just making sure we don't make breaking changes where we can avoid that.

@bluehallu
Copy link
Author

What about an optional flag to change this behaviour?

@elithrar
Copy link
Contributor

I'm open to that, if you have a proposal?
On Mon, Jun 20, 2016 at 3:42 AM bluehallu [email protected] wrote:

What about an optional flag to change this behaviour?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#124 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AABIcBmNGavIE74avrI54Cwp3QjqWWKtks5qNm6IgaJpZM4F5W0f
.

@bluehallu
Copy link
Author

bluehallu commented Jun 20, 2016

I'm afraid I only used Go once in my life, spotted this weird behaviour in one of the main libraries and reported it, but that's where my Mux knowledge ends. I don't think I'm in a position to make recommendations about how the Api for this library should be designed in any more detail than I already have. An optional boolean parameter "strict" comes to mind though :)

@themihai
Copy link

themihai commented Jun 25, 2016

I think a method StrictRegex on type Router[0] would work best. It would be in line with StrictSlash[1]. What do you think?

[0]

// StrictRegex defines the behaviour of HeadersRegexp, Host and regular expressions
// within the route paths. The initial value is false which means it wraps regexp 
// in wildcard by default.
func (r *Router) StrictRegex(value bool) *Router

[1] https://godoc.org/github.com/gorilla/mux#Router.StrictSlash

@elithrar
Copy link
Contributor

@themihai That would be great.

@mtso
Copy link
Contributor

mtso commented Nov 30, 2017

I'd like to add two examples to the documentation for Route.HeadersRegexp. I'm thinking of adding a new file named example_route_test.go using this article as a guide: https://blog.golang.org/examples.

The example file would contain two runnable examples:

  1. func ExampleRoute_HeadersRegexp() for the general behavior where the given pattern matches any substring of the header value.
  2. func ExampleRoute_HeadersRegexp_exactMatch() to show how to do a strict pattern that does an exact match with ^pattern$.

@kisielk
Copy link
Contributor

kisielk commented Nov 30, 2017

@mtso go for it!

@stale
Copy link

stale bot commented Dec 9, 2018

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

@stale stale bot added the stale label Dec 9, 2018
@stale stale bot closed this as completed Dec 17, 2018
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

5 participants