mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-17 23:26:02 +02:00
Special case for search_path in user options.
- search_path accepts a list of values that cannot be quoted, as quoting would make PostgreSQL interpret the result as a single value. Since we require quoting of values with commas in the operator's configMap in order to avoid confusing them with the separate map entities, we need to strip those quotes before passing the value to PostgreSQL. - make ftm run
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"reflect"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var getMapPairsFromStringTest = []struct {
|
||||
in string
|
||||
in string
|
||||
expected []string
|
||||
err error
|
||||
}{
|
||||
@@ -15,7 +15,7 @@ var getMapPairsFromStringTest = []struct {
|
||||
{`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")},
|
||||
{"", []string{""}, nil},
|
||||
{",,log_statement:all ,", []string{"","","log_statement:all", ""}, nil},
|
||||
{",,log_statement:all ,", []string{"", "", "log_statement:all", ""}, nil},
|
||||
}
|
||||
|
||||
func TestGetMapPairsFromString(t *testing.T) {
|
||||
@@ -29,4 +29,3 @@ func TestGetMapPairsFromString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,10 +169,10 @@ func processField(value string, field reflect.Value) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
type parserState int
|
||||
|
||||
const (
|
||||
Plain parserState = iota
|
||||
Plain parserState = iota
|
||||
DoubleQuoted
|
||||
SingleQuoted
|
||||
)
|
||||
@@ -180,12 +180,12 @@ const (
|
||||
// Split the pair candidates by commas not located inside open quotes
|
||||
// Escape characters are not supported for simplicity, as we don't
|
||||
// expect to find them inside the map values for our use cases
|
||||
func getMapPairsFromString(value string) (pairs []string , err error) {
|
||||
func getMapPairsFromString(value string) (pairs []string, err error) {
|
||||
pairs = make([]string, 0)
|
||||
state := Plain
|
||||
var start, quote int
|
||||
|
||||
for i, ch := range(strings.Split(value, "")) {
|
||||
for i, ch := range strings.Split(value, "") {
|
||||
if ch == `"` {
|
||||
if state == Plain {
|
||||
state = DoubleQuoted
|
||||
@@ -205,12 +205,12 @@ func getMapPairsFromString(value string) (pairs []string , err error) {
|
||||
}
|
||||
}
|
||||
if ch == "," && state == Plain {
|
||||
pairs = append(pairs, strings.Trim(value[start:i]," \t"))
|
||||
pairs = append(pairs, strings.Trim(value[start:i], " \t"))
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
if state != Plain {
|
||||
err = fmt.Errorf("unclosed quote starting at position %d", quote + 1)
|
||||
err = fmt.Errorf("unclosed quote starting at position %d", quote+1)
|
||||
pairs = nil
|
||||
} else {
|
||||
pairs = append(pairs, strings.Trim(value[start:], " \t"))
|
||||
|
||||
Reference in New Issue
Block a user