-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Do not replace import tokens if they are part of a snippet #5539
Conversation
I cannot get rid of the warning. Don't know a good way to hide these false positives. 😞 |
Oh, good, I like that you simplified the fix in that last commit. I thought it was weird that the tokens were passed in. |
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.
Thanks for the patch Weidi 😊
@mholt This patch changes the how variadic placeholders work. Now it cannot be used outside snippets. The way to fix it requires at least 2 passes and obviously, rewriting how caddy file parsing works. What do you think of it? |
I think the problem is snippets should be exempt from the replace rule but not. Implemented a naive way to check it. |
So, to be sure I'm clear on this, does this patch cause something to stop working? Based on the comments above, it sounds like using variadic placeholders, i.e. placeholders like |
Now they can be used in file as well, i.e. like other file imports do. There also won't be false warning about arguments index. |
Oh, wonderful -- that sounds like a good improvement. Thank you! @francislavoie just to double check you're good with this too? If so we can merge it 😊 |
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.
LGTM!
Thanks for the contribution, @WeidiDeng ! |
I think this has a bug: https://caddy.community/t/problem-after-upgrading-to-2-7-2/20687/6
With this config, the response will be I've observed that this only happens when the value is used in a snippet, and it does NOT happen when the JSON (Edit: Possibly fixed in #5685 ) |
As discussed in slack, if an imported file also has a snippet with variadic placeholders and imports this snippet, parsing will fail saying not enough arguments.Added tests show what the problem is.When importing, caddy will always replace tokens placeholders. However, when importing a file that contains snippets definition, caddy will replace them. For
{args[n]}
type token, they will either be replaced or dropped, which is undesirable since they are part of a snippet.Implement a naive algorithm to skip replacing tokens if they are part of a snippet. It does not check for syntax error, that will be done later when caddy finished importing all the tokens.