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: Allow nameless regexp placeholder shorthand #6113

Merged
merged 2 commits into from Mar 5, 2024

Conversation

francislavoie
Copy link
Member

@francislavoie francislavoie commented Feb 18, 2024

I just read the code for regexp matchers, and saw this:

	if mre.Name != "" {
		mre.phPrefix += "." + mre.Name
	}

This made me realize that we're always setting regexp placeholders, even if a name isn't specified... but our Caddyfile placeholder shorthand wasn't allowing {re.1}, it was only shortening long-form placeholders! Silly oversight...

Now, this is possible:

@match path_regexp ^/foo(.*)$
respond @match "{re.1}"

Specifying a name is only necessary if there's more than one matcher in the set (e.g. header_regexp + path_regexp at the same time), or if you want to carry the matcher result for later use if there's a risk that another regexp matcher might be used. But for the majority of cases, the simple case with no name is perfectly fine.

@francislavoie francislavoie added the bug 🐞 Something isn't working label Feb 18, 2024
@francislavoie francislavoie added this to the v2.8.0 milestone Feb 18, 2024
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.

Ah nice, thanks for fixing this.

@mholt mholt enabled auto-merge (squash) March 5, 2024 23:33
@mholt mholt merged commit 2a78c9c into master Mar 5, 2024
25 checks passed
@mholt mholt deleted the nameless-regexp-placeholder branch March 5, 2024 23:37
mholt pushed a commit that referenced this pull request Apr 17, 2024
* caddyfile: Populate regexp matcher names by default

* Some lint cleanup that my VSCode complained about

* Pass down matcher name through expression matcher

* Compat with #6113: fix adapt test, set both styles in replacer
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.

None yet

2 participants