-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
httpcaddyfile: Fix expression matcher shortcut in snippets #6288
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1282,19 +1282,24 @@ func matcherSetFromMatcherToken( | |
if tkn.Text == "*" { | ||
// match all requests == no matchers, so nothing to do | ||
return nil, true, nil | ||
} else if strings.HasPrefix(tkn.Text, "/") { | ||
// convenient way to specify a single path match | ||
} | ||
|
||
// convenient way to specify a single path match | ||
if strings.HasPrefix(tkn.Text, "/") { | ||
Comment on lines
+1285
to
+1288
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just don't like |
||
return caddy.ModuleMap{ | ||
"path": caddyconfig.JSON(caddyhttp.MatchPath{tkn.Text}, warnings), | ||
}, true, nil | ||
} else if strings.HasPrefix(tkn.Text, matcherPrefix) { | ||
// pre-defined matcher | ||
} | ||
|
||
// pre-defined matcher | ||
if strings.HasPrefix(tkn.Text, matcherPrefix) { | ||
m, ok := matcherDefs[tkn.Text] | ||
if !ok { | ||
return nil, false, fmt.Errorf("unrecognized matcher name: %+v", tkn.Text) | ||
} | ||
return m, true, nil | ||
} | ||
|
||
return nil, false, nil | ||
} | ||
|
||
|
@@ -1430,11 +1435,13 @@ func parseMatcherDefinitions(d *caddyfile.Dispenser, matchers map[string]caddy.M | |
if d.NextArg() { | ||
if d.Token().Quoted() { | ||
// since it was missing the matcher name, we insert a token | ||
// in front of the expression token itself | ||
err := makeMatcher("expression", []caddyfile.Token{ | ||
{Text: "expression", File: d.File(), Line: d.Line()}, | ||
d.Token(), | ||
}) | ||
// in front of the expression token itself; we use Clone() to | ||
// make the new token to keep the same the import location as | ||
// the next token, if this is within a snippet or imported file. | ||
// see https://github.com/caddyserver/caddy/issues/6287 | ||
expressionToken := d.Token().Clone() | ||
expressionToken.Text = "expression" | ||
err := makeMatcher("expression", []caddyfile.Token{expressionToken, d.Token()}) | ||
if err != nil { | ||
return err | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to make a
Clone()
because the token has some unexported fields that can't be copied from inside thehttpcaddyfile
package.