Skip to content

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 requested a review from mholt February 18, 2024 20:07
@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
@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.

2 participants