mirror of https://github.com/gofiber/fiber.git
Replaced double quotes with backticks in all route parameter strings (#2591)
* 11-aryan * Removed the backticks where no special characters is used * added backticks to path parameters where special characters are escaped * Replaced double quotes with backticks in all route parameter strings #2591 * Replaced double quotes with backticks in all route parameter strings #2591 --------- Co-authored-by: René Werner <rene@gofiber.io>pull/2617/head
parent
b932bf12fc
commit
328411a06b
|
@ -80,7 +80,7 @@ app.Get("/user/*", func(c *fiber.Ctx) error {
|
|||
})
|
||||
|
||||
// This route path will match requests to "/v1/some/resource/name:customVerb", since the parameter character is escaped
|
||||
app.Get("/v1/some/resource/name\\:customVerb", func(c *fiber.Ctx) error {
|
||||
app.Get(`/v1/some/resource/name\:customVerb`, func(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, Community")
|
||||
})
|
||||
```
|
||||
|
@ -90,7 +90,7 @@ Since the hyphen \(`-`\) and the dot \(`.`\) are interpreted literally, they can
|
|||
:::
|
||||
|
||||
:::info
|
||||
All special parameter characters can also be escaped with `"\\"` and lose their value, so you can use them in the route if you want, like in the custom methods of the [google api design guide](https://cloud.google.com/apis/design/custom_methods).
|
||||
All special parameter characters can also be escaped with `"\\"` and lose their value, so you can use them in the route if you want, like in the custom methods of the [google api design guide](https://cloud.google.com/apis/design/custom_methods). It's recommended to use backticks `` ` `` because in go's regex documentation, they always use backticks to make sure it is unambiguous and the escape character doesn't interfere with regex patterns in an unexpected way.
|
||||
:::
|
||||
|
||||
```go
|
||||
|
@ -203,7 +203,7 @@ app.Get("/:test<min(100);maxLen(5)>", func(c *fiber.Ctx) error {
|
|||
|
||||
Fiber precompiles regex query when to register routes. So there're no performance overhead for regex constraint.
|
||||
```go
|
||||
app.Get("/:date<regex(\\d{4}-\\d{2}-\\d{2})}>", func(c *fiber.Ctx) error {
|
||||
app.Get(`/:date<regex(\d{4}-\d{2}-\d{2})}>`, func(c *fiber.Ctx) error {
|
||||
return c.SendString(c.Params("date"))
|
||||
})
|
||||
|
||||
|
|
|
@ -85,21 +85,21 @@ func init() {
|
|||
},
|
||||
},
|
||||
{
|
||||
pattern: "/v1/some/resource/name\\:customVerb",
|
||||
pattern: `/v1/some/resource/name\:customVerb`,
|
||||
testCases: []routeTestCase{
|
||||
{url: "/v1/some/resource/name:customVerb", params: nil, match: true},
|
||||
{url: "/v1/some/resource/name:test", params: nil, match: false},
|
||||
},
|
||||
},
|
||||
{
|
||||
pattern: "/v1/some/resource/:name\\:customVerb",
|
||||
pattern: `/v1/some/resource/:name\:customVerb`,
|
||||
testCases: []routeTestCase{
|
||||
{url: "/v1/some/resource/test:customVerb", params: []string{"test"}, match: true},
|
||||
{url: "/v1/some/resource/test:test", params: nil, match: false},
|
||||
},
|
||||
},
|
||||
{
|
||||
pattern: "/v1/some/resource/name\\\\:customVerb?\\?/:param/*",
|
||||
pattern: `/v1/some/resource/name\\:customVerb?\?/:param/*`,
|
||||
testCases: []routeTestCase{
|
||||
{url: "/v1/some/resource/name:customVerb??/test/optionalWildCard/character", params: []string{"test", "optionalWildCard/character"}, match: true},
|
||||
{url: "/v1/some/resource/name:customVerb??/test", params: []string{"test", ""}, match: true},
|
||||
|
@ -572,7 +572,7 @@ func init() {
|
|||
},
|
||||
},
|
||||
{
|
||||
pattern: "/api/v1/:param<datetime(2006\\-01\\-02)>",
|
||||
pattern: `/api/v1/:param<datetime(2006\-01\-02)>`,
|
||||
testCases: []routeTestCase{
|
||||
{url: "/api/v1/entity", params: nil, match: false},
|
||||
{url: "/api/v1/8728382", params: nil, match: false},
|
||||
|
@ -598,7 +598,7 @@ func init() {
|
|||
},
|
||||
},
|
||||
{
|
||||
pattern: "/api/v1/:param<regex(\\d{4}-\\d{2}-\\d{2})}>",
|
||||
pattern: `/api/v1/:param<regex(\d{4}-\d{2}-\d{2})}>`,
|
||||
testCases: []routeTestCase{
|
||||
{url: "/api/v1/ent", params: nil, match: false},
|
||||
{url: "/api/v1/15", params: nil, match: false},
|
||||
|
@ -642,7 +642,7 @@ func init() {
|
|||
},
|
||||
},
|
||||
{
|
||||
pattern: "/api/v1/:param<int\\;range(10,30)>",
|
||||
pattern: `/api/v1/:param<int\;range(10,30)>`,
|
||||
testCases: []routeTestCase{
|
||||
{url: "/api/v1/entity", params: []string{"entity"}, match: true},
|
||||
{url: "/api/v1/87283827683", params: []string{"87283827683"}, match: true},
|
||||
|
@ -651,7 +651,7 @@ func init() {
|
|||
},
|
||||
},
|
||||
{
|
||||
pattern: "/api/v1/:param<range(10\\,30,1500)>",
|
||||
pattern: `/api/v1/:param<range(10\,30,1500)>`,
|
||||
testCases: []routeTestCase{
|
||||
{url: "/api/v1/entity", params: nil, match: false},
|
||||
{url: "/api/v1/87283827683", params: nil, match: false},
|
||||
|
@ -697,7 +697,7 @@ func init() {
|
|||
},
|
||||
},
|
||||
{
|
||||
pattern: "/api/v1/:date<datetime(2006\\-01\\-02)>/:regex<regex(p([a-z]+)ch)>",
|
||||
pattern: `/api/v1/:date<datetime(2006\-01\-02)>/:regex<regex(p([a-z]+)ch)>`,
|
||||
testCases: []routeTestCase{
|
||||
{url: "/api/v1/2005-11-01/a", params: nil, match: false},
|
||||
{url: "/api/v1/2005-1101/paach", params: nil, match: false},
|
||||
|
|
Loading…
Reference in New Issue