Skip to content
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

replacer: Fix escaped closing braces #5995

Merged

Conversation

armadi1809
Copy link
Contributor

Resolves #5993. Inside func (r *Replacer) replace we were returning the same input if it does not contain the opening brace but which meant that we were not treating the closing brace as a character that should be escaped.

@mohammed90
Copy link
Member

Thank you for looking into the fix! Would you mind adding test cases? You can consider the reported config/behavior as one. If you can come up with more scenarios, that'd be great.

@armadi1809 armadi1809 force-pushed the closing-bracket-replacement-bug branch from 6acb8fc to 2e5e63a Compare December 19, 2023 06:59
@francislavoie francislavoie changed the title Fixed uri replace bug with closing brackets replacer: Fix escaped closing braces Dec 19, 2023
@armadi1809
Copy link
Contributor Author

@mohammed90 I have a question. One of the tests that are currently present (And which I had to change to pass the checks) states that func (r *Replacer) ReplaceAll should return \} when the input is \}. Shouldn't it be } as the backslash is used to escape the brace and hence should be removed? Because a similar test exists with the opening brace and the backslash is indeed removed.

I am asking because I may be missing an intended behavior here. Thank you.

@mohammed90
Copy link
Member

@mohammed90 I have a question. One of the tests that are currently present (And which I had to change to pass the checks) states that func (r *Replacer) ReplaceAll should return \} when the input is \}. Shouldn't it be } as the backslash is used to escape the brace and hence should be removed? Because a similar test exists with the opening brace and the backslash is indeed removed.

I am asking because I may be missing an intended behavior here. Thank you.

Checking git blame on that line shows it was added as part of PR #3121 to resolve #3116. I believe it's intended, but I'm not firm on this. I need to think about it, especially because that area of the code is not very familiar to me. Perhaps Francis or Matt can chime in.

@francislavoie
Copy link
Member

francislavoie commented Dec 19, 2023

Yeah looks weird to me, but also I don't think escaping was necessary at all in the reported issue.

I don't have any objections to this, collapsing escapes seems fine to me here (as long as \\} still works to output \} literally).

But yeah we should have some more test cases to make sure this change is bulletproof.

@armadi1809
Copy link
Contributor Author

Thank you guys for the prompt responses. I will work on adding more test cases.

@armadi1809
Copy link
Contributor Author

I just added a couple tests. Please let me know if you want to see more cases covered. Thank you!

Copy link
Member

@mohammed90 mohammed90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, just a few minor nitpicks from my side.

caddytest/integration/caddyfile_test.go Outdated Show resolved Hide resolved
caddytest/integration/caddyfile_test.go Outdated Show resolved Hide resolved
@armadi1809 armadi1809 force-pushed the closing-bracket-replacement-bug branch from 13cd757 to 8a154ba Compare December 22, 2023 19:32
@armadi1809
Copy link
Contributor Author

@mohammed90 Thank you for taking the time to review! All your feedback points should now be addressed.

Copy link
Member

@francislavoie francislavoie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@francislavoie francislavoie added the bug 🐞 Something isn't working label Jan 13, 2024
@francislavoie francislavoie added this to the v2.8.0 milestone Jan 13, 2024
@francislavoie francislavoie enabled auto-merge (squash) January 13, 2024 20:20
@francislavoie francislavoie merged commit 80acf1b into caddyserver:master Jan 13, 2024
25 checks passed
@mholt
Copy link
Member

mholt commented Jan 17, 2024

@armadi1809 Thank you for your contribution! Please feel welcome to contribute again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Caddy 2.7: uri replace does not work with closing brackets ( '}' )
4 participants