-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
caddy.go: Check whether @id is unique #7002
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
base: master
Are you sure you want to change the base?
Conversation
err2 := rollbackRawCfg() | ||
if err2 != nil { | ||
err = errors.Join(err, err2) | ||
} |
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.
Trying to parse the old config here without checking the length of rawCfgJSON
isn't a recommended approach. Additionally, this is a potential duplicate of the call in Ln246
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.
May I ask if there are any areas in this pr that need to be modified and if it can be merged?
caddy.go
Outdated
err := json.Unmarshal(rawCfgJSON, &oldCfg) | ||
rawCfg[rawConfigKey] = oldCfg |
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.
obs: Potential nil assignment to rawCfg
. Check for error before assigning to the map
I added length detection and fixed a stupid problem. From the perspective of code analysis, "err" will not be repeated. Changes of rewrite, involves nginx-adapter-case |
Please keep the PR topical and focused. Split these changes into a separate PR. |
I have deleted the irrelevant pr |
I feel like a better approach would be to check the ID as it's being read in and we're creating the mapping of IDs to their full config paths. If we return an error the rest should be handled automatically (no need to roll back, etc) |
If we do as you said, the content that needs to be modified is rather complicated. This is beyond my ability. I'm worried that the modification will introduce bugs. |
add one test. |
Fixes: #6991
Check whether @id is unique.If it is not unique,rollback caddy config json.
I'm not sure if it can work properly under caddyfile.