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

Fix broken block parsing when label prefix contains dots #610

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"os"
"regexp"
"strings"
"time"

"github.com/docker/docker/api/types"
Expand Down Expand Up @@ -38,7 +39,7 @@ type CaddyfileGenerator struct {

// CreateGenerator creates a new generator
func CreateGenerator(dockerClients []docker.Client, dockerUtils docker.Utils, options *config.Options) *CaddyfileGenerator {
var labelRegexString = fmt.Sprintf("^%s(_\\d+)?(\\.|$)", options.LabelPrefix)
var labelRegexString = fmt.Sprintf("^%s(_\\d+)?(\\.|$)", regexp.QuoteMeta(options.LabelPrefix))
Copy link
Author

Choose a reason for hiding this comment

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

Here uses regexp.QuoteMeta to escapes all regular expression metacharacters in the user-provided label prefix, to make it a literal text in the labelRegex.


return &CaddyfileGenerator{
options: options,
Expand Down Expand Up @@ -284,6 +285,8 @@ func (g *CaddyfileGenerator) filterLabels(labels map[string]string) map[string]s
filteredLabels := map[string]string{}
for label, value := range labels {
if g.labelRegex.MatchString(label) {
// Canonicalize label prefix to "caddy", to prevent any meta characters in the prefix from causing problem in block parsing
label = strings.Replace(label, g.options.LabelPrefix, "caddy", 1)
filteredLabels[label] = value
}
}
Expand Down
Loading