Skip to content

Commit

Permalink
fileserver: fix try_policy when instantiating file matcher from CEL
Browse files Browse the repository at this point in the history
  • Loading branch information
effleurager committed Oct 13, 2024
1 parent 48ce47f commit 8bb71ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/caddyhttp/fileserver/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (MatchFile) CELLibrary(ctx caddy.Context) (cel.Library, error) {

var try_policy string
if len(values["try_policy"]) > 0 {
root = values["try_policy"][0]
try_policy = values["try_policy"][0]
}

m := MatchFile{
Expand Down
8 changes: 8 additions & 0 deletions modules/caddyhttp/fileserver/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ var expressionTests = []struct {
urlTarget: "https://example.com/nopenope.txt",
wantResult: false,
},
{
name: "file match long pattern foo.txt with try_policy (MatchFile)",
expression: &caddyhttp.MatchExpression{
Expr: `file({"try_policy": "most_recently_modified"})`,
},
urlTarget: "https://example.com/foo.txt",
wantResult: true,
},
}

func TestMatchExpressionMatch(t *testing.T) {
Expand Down

0 comments on commit 8bb71ce

Please # to comment.