summaryrefslogtreecommitdiff
path: root/caddyconfig
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2021-12-13 13:42:08 -0500
committerGitHub <noreply@github.com>2021-12-13 13:42:08 -0500
commit81ee34e9623c3ac630f46c81a26e7823d0b2bf7b (patch)
tree6c32a15a3fbe5f631728b7b4b4f3a47415f02fd5 /caddyconfig
parent78b5356f2b1945a90de1ef7f2c7669d82098edbd (diff)
httpcaddyfile: Fix sorting edgecase for nested `handle_path` (#4477)
Diffstat (limited to 'caddyconfig')
-rw-r--r--caddyconfig/httpcaddyfile/directives.go3
-rw-r--r--caddyconfig/httpcaddyfile/httptype.go21
2 files changed, 17 insertions, 7 deletions
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go
index 9da205e..8d895dd 100644
--- a/caddyconfig/httpcaddyfile/directives.go
+++ b/caddyconfig/httpcaddyfile/directives.go
@@ -340,6 +340,9 @@ func parseSegmentAsConfig(h Helper) ([]ConfigValue, error) {
if err != nil {
return nil, h.Errf("parsing caddyfile tokens for '%s': %v", dir, err)
}
+
+ dir = normalizeDirectiveName(dir)
+
for _, result := range results {
result.directive = dir
allResults = append(allResults, result)
diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go
index bc01060..3a54c08 100644
--- a/caddyconfig/httpcaddyfile/httptype.go
+++ b/caddyconfig/httpcaddyfile/httptype.go
@@ -193,13 +193,7 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,
return nil, warnings, fmt.Errorf("parsing caddyfile tokens for '%s': %v", dir, err)
}
- // As a special case, we want "handle_path" to be sorted
- // at the same level as "handle", so we force them to use
- // the same directive name after their parsing is complete.
- // See https://github.com/caddyserver/caddy/issues/3675#issuecomment-678042377
- if dir == "handle_path" {
- dir = "handle"
- }
+ dir = normalizeDirectiveName(dir)
for _, result := range results {
result.directive = dir
@@ -1061,6 +1055,19 @@ func buildSubroute(routes []ConfigValue, groupCounter counter) (*caddyhttp.Subro
return subroute, nil
}
+// normalizeDirectiveName ensures directives that should be sorted
+// at the same level are named the same before sorting happens.
+func normalizeDirectiveName(directive string) string {
+ // As a special case, we want "handle_path" to be sorted
+ // at the same level as "handle", so we force them to use
+ // the same directive name after their parsing is complete.
+ // See https://github.com/caddyserver/caddy/issues/3675#issuecomment-678042377
+ if directive == "handle_path" {
+ directive = "handle"
+ }
+ return directive
+}
+
// consolidateRoutes combines routes with the same properties
// (same matchers, same Terminal and Group settings) for a
// cleaner overall output.