Warn about attempts to use escape quotes.

This commit is contained in:
Oleksii Kliukin 2017-11-20 16:57:22 +01:00
parent f6a2225c38
commit 086ead03f5
3 changed files with 7 additions and 3 deletions

View File

@ -72,7 +72,7 @@ type Config struct {
RingLogLines int `name:"ring_log_lines" default:"100"`
ClusterHistoryEntries int `name:"cluster_history_entries" default:"1000"`
TeamAPIRoleConfiguration map[string]string `name:"team_api_role_configuration" default:"log_statement:'all'"`
PodTerminateGracePeriod time.Duration `name:"pod_terminate_grace_period" default:"5m"`
PodTerminateGracePeriod time.Duration `name:"pod_terminate_grace_period" default:"5m"`
}
// MustMarshal marshals the config or panics

View File

@ -13,7 +13,7 @@ var getMapPairsFromStringTest = []struct {
}{
{"log_statement:all, work_mem:'4GB'", []string{"log_statement:all", "work_mem:'4GB'"}, nil},
{`log_statement:none, search_path:'"$user", public'`, []string{"log_statement:none", `search_path:'"$user", public'`}, nil},
{`search_path:'"$user"`, nil, fmt.Errorf("unclosed quote starting at position 13")},
{`search_path:'"$user"`, nil, fmt.Errorf("unmatched quote starting at position 13")},
{"", []string{""}, nil},
{",,log_statement:all ,", []string{"", "", "log_statement:all", ""}, nil},
}

View File

@ -175,6 +175,7 @@ const (
Plain parserState = iota
DoubleQuoted
SingleQuoted
Escape
)
// Split the pair candidates by commas not located inside open quotes
@ -186,6 +187,9 @@ func getMapPairsFromString(value string) (pairs []string, err error) {
var start, quote int
for i, ch := range strings.Split(value, "") {
if (ch == `"` || ch == `'`) && i > 0 && value[i-1] == '\\' {
fmt.Printf("Parser warning: ecape character '\\' have no effect on quotes inside the configuration value %s\n", value)
}
if ch == `"` {
if state == Plain {
state = DoubleQuoted
@ -210,7 +214,7 @@ func getMapPairsFromString(value string) (pairs []string, err error) {
}
}
if state != Plain {
err = fmt.Errorf("unclosed quote starting at position %d", quote+1)
err = fmt.Errorf("unmatched quote starting at position %d", quote+1)
pairs = nil
} else {
pairs = append(pairs, strings.Trim(value[start:], " \t"))