Warn about attempts to use escape quotes.
This commit is contained in:
parent
f6a2225c38
commit
086ead03f5
|
|
@ -72,7 +72,7 @@ type Config struct {
|
||||||
RingLogLines int `name:"ring_log_lines" default:"100"`
|
RingLogLines int `name:"ring_log_lines" default:"100"`
|
||||||
ClusterHistoryEntries int `name:"cluster_history_entries" default:"1000"`
|
ClusterHistoryEntries int `name:"cluster_history_entries" default:"1000"`
|
||||||
TeamAPIRoleConfiguration map[string]string `name:"team_api_role_configuration" default:"log_statement:'all'"`
|
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
|
// MustMarshal marshals the config or panics
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ var getMapPairsFromStringTest = []struct {
|
||||||
}{
|
}{
|
||||||
{"log_statement:all, work_mem:'4GB'", []string{"log_statement:all", "work_mem:'4GB'"}, nil},
|
{"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},
|
{`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},
|
{"", []string{""}, nil},
|
||||||
{",,log_statement:all ,", []string{"", "", "log_statement:all", ""}, nil},
|
{",,log_statement:all ,", []string{"", "", "log_statement:all", ""}, nil},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,6 +175,7 @@ const (
|
||||||
Plain parserState = iota
|
Plain parserState = iota
|
||||||
DoubleQuoted
|
DoubleQuoted
|
||||||
SingleQuoted
|
SingleQuoted
|
||||||
|
Escape
|
||||||
)
|
)
|
||||||
|
|
||||||
// Split the pair candidates by commas not located inside open quotes
|
// 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
|
var start, quote int
|
||||||
|
|
||||||
for i, ch := range strings.Split(value, "") {
|
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 ch == `"` {
|
||||||
if state == Plain {
|
if state == Plain {
|
||||||
state = DoubleQuoted
|
state = DoubleQuoted
|
||||||
|
|
@ -210,7 +214,7 @@ func getMapPairsFromString(value string) (pairs []string, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if state != Plain {
|
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
|
pairs = nil
|
||||||
} else {
|
} else {
|
||||||
pairs = append(pairs, strings.Trim(value[start:], " \t"))
|
pairs = append(pairs, strings.Trim(value[start:], " \t"))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue