From 328411a06b674371bc2a732250f5ac5409446979 Mon Sep 17 00:00:00 2001 From: ")`(-@_.+_^*__*^" <55359898+11-aryan@users.noreply.github.com> Date: Mon, 4 Sep 2023 09:10:44 +0530 Subject: [PATCH] Replaced double quotes with backticks in all route parameter strings (#2591) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- docs/guide/routing.md | 6 +++--- path_testcases_test.go | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/guide/routing.md b/docs/guide/routing.md index 2d97ede4c8..7b092461ce 100644 --- a/docs/guide/routing.md +++ b/docs/guide/routing.md @@ -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", 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", func(c *fiber.Ctx) error { +app.Get(`/:date`, func(c *fiber.Ctx) error { return c.SendString(c.Params("date")) }) diff --git a/path_testcases_test.go b/path_testcases_test.go index 5602a0284d..26ec5b748e 100644 --- a/path_testcases_test.go +++ b/path_testcases_test.go @@ -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", + pattern: `/api/v1/:param`, 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", + pattern: `/api/v1/:param`, 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", + pattern: `/api/v1/:param`, 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", + pattern: `/api/v1/:param`, 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/:regex", + pattern: `/api/v1/:date/:regex`, testCases: []routeTestCase{ {url: "/api/v1/2005-11-01/a", params: nil, match: false}, {url: "/api/v1/2005-1101/paach", params: nil, match: false},