-
-
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
Fix two import problems: snippets and import literals. #2205
Conversation
Two problems are fixed by this code simplification: 1. Snippets defined in one import file are strangely not available in another. 2. If an imported file had a directive with an argument "import", then the rest of the tokens on the line would be converted to absolute filepaths. An example of caddyserver#2 would be the following directive in an imported file: basicauth / import secret In this case, the password would actually be an absolute path to the file 'secret' (whether or not it exists) in the directory of the imported Caddyfile. The problem was the blind token processing to fix import paths in the imported tokens without considering the context of the 'import' token. My first inclination was to just add more context (detect 'import' tokens at the beginning of lines and check the value tokens against defined snippets), however I eventually realized that we already do all of this in the parser, so the code was redundant. Instead we just use the current token's File property when importing. This works fine with imported tokens since they already have the absolute path to the imported file! Fixes caddyserver#2204
853a60b
to
def73ff
Compare
Ooo, nice! I'm looking forward to going over these changes. Of course, I invite any other collaborators to give it a review too, since they'll probably be able to sooner than I am. |
caddyfile/parse_test.go
Outdated
} | ||
|
||
func TestImportedFilesIgnoreNonDirectiveImportTokens(t *testing.T) { | ||
file2 := writeStringToTempFileOrDie(t, ` |
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.
Can you name it just fileName
for readability?
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.
sure, renamed
This makes it more clear how the import side effect is detrimental.
ping? Is this ready to merge? |
Thanks @augustoroman -- I love how the solution was basically to delete code and add tests. If you'd like to be a collaborator on the project to help review PRs and issues and get push access, let me know. :) |
caddyfile: Fix multi-file snippets and import literals. (caddyserver#2205)
Two problems are fixed by this code simplification:
another.
the rest of the tokens on the line would be converted to absolute
filepaths.
An example of 2 would be the following directive in an imported file:
In this case, the password would actually be an absolute path to the
file 'secret' (whether or not it exists) in the directory of the imported
Caddyfile.
The problem was the blind token processing to fix import paths in the
imported tokens without considering the context of the 'import' token.
My first inclination was to just add more context (detect 'import' tokens
at the beginning of lines and check the value tokens against defined
snippets), however I eventually realized that we already do all of this
in the parser, so the code was redundant. Instead we just use the current
token's File property when importing. This works fine with imported tokens
since they already have the absolute path to the imported file!
Fixes #2204