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

caddyfile: Fix comma edgecase in address parsing #6616

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

francislavoie
Copy link
Member

When the site address line looks like foo , bar (i.e. spaces around the , and not simply a comma trailing an address), then it would cause the site address to include an empty space which messes up parsing in subtle ways. This fixes that case.

Closes caddyserver/website#395

Given this Caddyfile:

foo.example.com , example.com , www.example.com {
    respond "foo"
}

Before (for some reason, no host matchers are produced, but it does automate the names):

{"apps":{"http":{"servers":{"srv0":{"listen":[":443"],"routes":[{"handle":[{"body":"foo","handler":"static_response"}]}]}}},"tls":{"certificates":{"automate":["foo.example.com","example.com","www.example.com"]}}}}

After (properly matching the hosts, later resulting in Auto HTTPS automating):

{"apps":{"http":{"servers":{"srv0":{"listen":[":443"],"routes":[{"match":[{"host":["foo.example.com","example.com","www.example.com"]}],"handle":[{"handler":"subroute","routes":[{"handle":[{"body":"foo","handler":"static_response"}]}]}],"terminal":true}]}}}}}

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.

Could we do this better by changing if value[len(value)-1] == ',' { to if value[len(value)-1] == ',' && len(strings.TrimSpace(value)) > 1 { ?

@francislavoie
Copy link
Member Author

francislavoie commented Oct 10, 2024

No because that would ignore the comma (not trim it) then pass the "contains ," condition, throwing an error. We want to just ignore a bare ,.

--- FAIL: TestParseAll (0.00s)
    caddy/caddyconfig/caddyfile/parse_test.go:611: Test 4: Expected no error, but got: Site addresses cannot contain a comma ',': ',' - put a space after the comma to separate site addresses, at Testfile:1
    caddy/caddyconfig/caddyfile/parse_test.go:615: Test 4: Expected 1 server blocks, got 0

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 okay. This works then.

@francislavoie francislavoie enabled auto-merge (squash) October 10, 2024 20:21
@francislavoie francislavoie merged commit ef4e022 into master Oct 10, 2024
33 checks passed
@francislavoie francislavoie deleted the address-parse-commas branch October 10, 2024 20:27
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.

matcher format for multiple sites share same definition
2 participants