Skip to content

Improve Caddyfile parsing to disambiguate when braces are missing #1998

@francislavoie

Description

@francislavoie

Just an issue to track the sub-discussion that was had in #1973, also relating to #550.

See https://caddyserver.com/docs/caddyfile#structure

Caddyfiles allow omitting { } when there's only a single label (domain/url identifier to serve on). A problem arises when an import might be used (either by the new glob feature recently merged in, or explicitly in the main Caddyfile). The imported files might not be using { }, so this would cause parsing errors.

The idea is for the fix would be that the parser could artificially wrap the blocks that don't have { } with those, to avoid the parsing problems.

The tricky bit is figuring out when the label definitions end, because it's allowed for them to be multi-line. For multi-line, each line must end with a , (some whitespace following it is allowed) for the label parsing to continue. While label parsing, we should detect the first newline without a , and end parsing the label there - which also means we can insert a { at that time, remember that we did so, and continue parsing. When we reach the end of the file (when importing), then we can add a } if we added a { earlier.

I think that covers everything. @mholt ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussion 💬The right solution needs to be foundfeature ⚙️New feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions