Skip to content

Commit

Permalink
Replaced double quotes with backticks in all route parameter strings (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
11-aryan and ReneWerner87 authored Sep 4, 2023
1 parent b932bf1 commit 328411a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions docs/guide/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
```
Expand All @@ -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
Expand Down Expand Up @@ -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"))
})

Expand Down
16 changes: 8 additions & 8 deletions path_testcases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -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},
Expand All @@ -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},
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 328411a

Please sign in to comment.