Compare commits

...

5 Commits

Author SHA1 Message Date
atennop
5bd9e3061b
Merge 8596512f4fdb118a3c134de8300d7d917a9e3d78 into 5f4f9643258dc2a65e684b63f12c8d543c936c67 2026-05-15 04:09:16 +08:00
dependabot[bot]
5f4f964325
chore(deps): bump the actions group across 1 directory with 2 updates (#4640)
Bumps the actions group with 2 updates in the / directory: [codecov/codecov-action](https://github.com/codecov/codecov-action) and [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action).


Updates `codecov/codecov-action` from 5 to 6
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v5...v6)

Updates `aquasecurity/trivy-action` from 0.35.0 to 0.36.0
- [Release notes](https://github.com/aquasecurity/trivy-action/releases)
- [Commits](https://github.com/aquasecurity/trivy-action/compare/0.35.0...v0.36.0)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: aquasecurity/trivy-action
  dependency-version: 0.36.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-09 10:20:32 +08:00
Bo-Yi Wu
8596512f4f
Merge branch 'master' into changed-trailing-slash-redirection-behaviour 2026-02-28 21:08:30 +08:00
Atennop1
18d33bd738 fix: updated documentation 2026-01-15 16:40:45 +03:00
Atennop1
12ed1b1715 feat: RedirectTrailingSlash(false) now assumes that /path and /path/ are the same 2026-01-15 16:38:12 +03:00
4 changed files with 38 additions and 18 deletions

View File

@ -78,6 +78,6 @@ jobs:
run: make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
uses: codecov/codecov-action@v6
with:
flags: ${{ matrix.os }},go-${{ matrix.go }},${{ matrix.test-tags }}

View File

@ -27,7 +27,7 @@ jobs:
fetch-depth: 0
- name: Run Trivy vulnerability scanner (source code)
uses: aquasecurity/trivy-action@0.35.0
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: "fs"
scan-ref: "."
@ -44,7 +44,7 @@ jobs:
sarif_file: "trivy-results.sarif"
- name: Run Trivy scanner (table output for logs)
uses: aquasecurity/trivy-action@0.35.0
uses: aquasecurity/trivy-action@v0.36.0
if: always()
with:
scan-type: "fs"

42
gin.go
View File

@ -101,6 +101,8 @@ type Engine struct {
// For example if /foo/ is requested but a route only exists for /foo, the
// client is redirected to /foo with http status code 301 for GET requests
// and 307 for all other request methods.
// If this field is false then /foo and /foo/ are assumed the same and no redirection will happen,
// both endpoints will use the same handlers.
RedirectTrailingSlash bool
// RedirectFixedPath if enabled, the router tries to fix the current request path, if no
@ -712,21 +714,39 @@ func (engine *Engine) handleHTTPRequest(c *Context) {
}
root := t[i].root
// Find route in tree
value := root.getValue(rPath, c.params, c.skippedNodes, unescape)
if value.params != nil {
c.Params = *value.params
isRouteFound := func(value nodeValue) bool {
if value.params != nil {
c.Params = *value.params
}
if value.handlers != nil {
c.handlers = value.handlers
c.fullPath = value.fullPath
c.Next()
c.writermem.WriteHeaderNow()
return true
}
return false
}
if value.handlers != nil {
c.handlers = value.handlers
c.fullPath = value.fullPath
c.Next()
c.writermem.WriteHeaderNow()
value := root.getValue(rPath, c.params, c.skippedNodes, unescape)
if isRouteFound(value) {
return
}
if httpMethod != http.MethodConnect && rPath != "/" {
if value.tsr && engine.RedirectTrailingSlash {
redirectTrailingSlash(c)
return
if value.tsr {
if engine.engine.RedirectTrailingSlash {
redirectTrailingSlash(c)
return
}
newRPath := rPath + "/"
if rPath[len(rPath)-1] == '/' {
newRPath = rPath[:len(rPath)-1]
}
value = root.getValue(newRPath, c.params, c.skippedNodes, unescape)
if isRouteFound(value) {
return
}
}
if engine.RedirectFixedPath && redirectFixedPath(c, root, engine.RedirectFixedPath) {
return

View File

@ -237,13 +237,13 @@ func TestRouteRedirectTrailingSlash(t *testing.T) {
router.RedirectTrailingSlash = false
w = PerformRequest(router, http.MethodGet, "/path/")
assert.Equal(t, http.StatusNotFound, w.Code)
assert.Equal(t, http.StatusOK, w.Code)
w = PerformRequest(router, http.MethodGet, "/path2")
assert.Equal(t, http.StatusNotFound, w.Code)
assert.Equal(t, http.StatusOK, w.Code)
w = PerformRequest(router, http.MethodPost, "/path3/")
assert.Equal(t, http.StatusNotFound, w.Code)
assert.Equal(t, http.StatusOK, w.Code)
w = PerformRequest(router, http.MethodPut, "/path4")
assert.Equal(t, http.StatusNotFound, w.Code)
assert.Equal(t, http.StatusOK, w.Code)
}
func TestRouteRedirectFixedPath(t *testing.T) {