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

httpcaddyfile: Adjust path matcher sorting to solve for specificity #5462

Merged
merged 1 commit into from
Mar 27, 2023

Conversation

francislavoie
Copy link
Member

Our existing Caddyfile path matcher sorting has served us quite well, but I only just thought of one edgecase we didn't handle very well.

In the case that the user defines both /foo and /foo* matchers on the same directive type, previously it would sort /foo* first because it's a longer path matcher (more chars).

The problem is, technically /foo is more specific because * matches 0 or more characters. So we need to reverse the order of those when the paths are the same other than having a * suffix.

Also, I took the liberty of refactoring the implementation a bit to use an inline function to deduplicate the condition. That was my fault when I introduced the case for handling vars being reversed.

@francislavoie francislavoie requested a review from mholt March 27, 2023 04:58
@francislavoie francislavoie added the bug 🐞 Something isn't working label Mar 27, 2023
@francislavoie francislavoie added this to the v2.7.0 milestone Mar 27, 2023
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

An elegant patch, with tests. Thank you for this!

@francislavoie francislavoie merged commit 330be2d into master Mar 27, 2023
@francislavoie francislavoie deleted the path-matcher-sorting branch March 27, 2023 19:43
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.

2 participants