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

Literal colons in URLs #1432

Closed
david-l-riley opened this issue Jul 17, 2018 · 11 comments
Closed

Literal colons in URLs #1432

david-l-riley opened this issue Jul 17, 2018 · 11 comments

Comments

@david-l-riley
Copy link

I'm working on a project which uses literal colons in URLs to specify custom methods, as per the Google API Design Guidelines. The colons do not come after a slash, as one would expect a variable to, but the engine will detect them as variables anyway because it does a simple search for single colon or asterisk characters in tree.go (in several places).

I'd like to be able to include literal colons (not necessarily asterisks, though I don't see why not) in URLs because they're valid characters, either normally when they're not immediately after a path delimiter (do we really support having paths like /root/version/something:variable?) or if they're backslash-escaped. I can make a PR to do this, but I'd like to get a sense of what's preferred (if not both).

@syssam
Copy link
Contributor

syssam commented Jul 18, 2018

Gin is using HttpRouter, maybe you can make pr on the HttpRouter.
Here also have same issue, however, does not slove.
julienschmidt/httprouter#196

Or, You can using some/resource/name:customVerb then checking :customVerb is valid or not on the middleware.Although, It seems ugly, but it is easily than PR.

@david-l-riley
Copy link
Author

More than ugly, it's not particularly efficient; a lot of httprouter's runtime efficiency is due to the absence of checks like this (they're all done at route build time, not query time).

A PR wouldn't be hard, honestly. I'm happy to make one as long as my solution is acceptable. I asked here because Gin uses a customized fork of httprouter, so patching the upstream (which I've also proposed) won't help here.

Echo has the same problem, FWIW... it seems like no one is considering this problem, which seems weird.

@syssam
Copy link
Contributor

syssam commented Jul 18, 2018

@david-l-riley
Right, it is lower efficient
Echo also using HttpRouter, so it has the same issue.
Although Gin uses a customized HttpRouter, but core does not changed.
I think you can make PR on the HttpRouter firstly.
I did not use ":" as URL and did not see ":" at any API Service or Website before, so one is considering this problem, um...

@david-l-riley
Copy link
Author

It's been part of the Google API design guide for quite a while for defining custom methods, but in general, I am surprised that the concept of escaping special characters in the URL definition isn't considered. It artificially constrains the available URL space when you make it impossible to use otherwise-valid characters in a URL, and a colon isn't an especially unusual one (an asterisk, maybe).

Anyway, I've made a contribution to the discussion on the httprouter issue, and will make a PR there if need be; if anything comes of it, I'll note it here.

@john8329
Copy link

john8329 commented Jan 6, 2020

Stumbled on the same issue here, the only reasonable solution seems to use another URL-valid character, like '~' or '.'
The dot seems nicer, as it looks like method call, but at this point it's just an invented standard with the purpose of replacing a lacking feature.

wssccc added a commit to wssccc/gin that referenced this issue Sep 6, 2021
wssccc added a commit to wssccc/gin that referenced this issue Sep 6, 2021
wssccc added a commit to wssccc/gin that referenced this issue Sep 6, 2021
wssccc added a commit to wssccc/gin that referenced this issue Sep 6, 2021
wssccc added a commit to wssccc/gin that referenced this issue Sep 6, 2021
wssccc added a commit to wssccc/gin that referenced this issue Sep 6, 2021
wssccc added a commit to wssccc/gin that referenced this issue Sep 6, 2021
wssccc added a commit to wssccc/gin that referenced this issue Sep 6, 2021
wssccc added a commit to wssccc/gin that referenced this issue Sep 6, 2021
wssccc added a commit to wssccc/gin that referenced this issue Sep 7, 2021
wssccc added a commit to wssccc/gin that referenced this issue Sep 7, 2021
@NgZiming
Copy link

encountered same issue.

@wssccc 's pr looks nice.

will it be accepted by next release?

wssccc added a commit to wssccc/gin that referenced this issue Apr 22, 2022
wssccc added a commit to wssccc/gin that referenced this issue Apr 22, 2022
@hyp0th3rmi4
Copy link

hyp0th3rmi4 commented Oct 24, 2022

Hello is there any update on this matter?

@leefernandes
Copy link

leefernandes commented Apr 10, 2023

Does httprouter not support specifying a named parameter prefix alternatively to :?

@grindlife
Copy link

Hello is there any update on this matter?

@ndreno
Copy link

ndreno commented Feb 1, 2024

no news?

wssccc added a commit to wssccc/gin that referenced this issue May 23, 2024
wssccc added a commit to wssccc/gin that referenced this issue May 23, 2024
wssccc added a commit to wssccc/gin that referenced this issue May 23, 2024
wssccc added a commit to wssccc/gin that referenced this issue May 23, 2024
wssccc added a commit to wssccc/gin that referenced this issue May 23, 2024
wssccc added a commit to wssccc/gin that referenced this issue May 24, 2024
wssccc added a commit to wssccc/gin that referenced this issue May 24, 2024
wssccc added a commit to wssccc/gin that referenced this issue May 25, 2024
@appleboy
Copy link
Member

appleboy commented Jun 1, 2024

fixed in #2857

@appleboy appleboy closed this as completed Jun 1, 2024
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

9 participants