support for equals in yaml-style lines

pull/34/head
Alex Quick 2017-05-20 15:06:01 -04:00
parent 84bf91f40e
commit 6f30f0c011
2 changed files with 10 additions and 4 deletions

View File

@ -198,11 +198,11 @@ func parseLine(line string) (key string, value string, err error) {
line = strings.Join(segmentsToKeep, "#") line = strings.Join(segmentsToKeep, "#")
} }
// now split key from value firstEquals := strings.Index(line, "=")
firstColon := strings.Index(line, ":")
splitString := strings.SplitN(line, "=", 2) splitString := strings.SplitN(line, "=", 2)
if firstColon != -1 && (firstColon < firstEquals || firstEquals == -1) {
if len(splitString) != 2 { //this is a yaml-style line
// try yaml mode!
splitString = strings.SplitN(line, ":", 2) splitString = strings.SplitN(line, ":", 2)
} }

View File

@ -205,6 +205,12 @@ func TestParsing(t *testing.T) {
// parses yaml style options // parses yaml style options
parseAndCompare(t, "OPTION_A: 1", "OPTION_A", "1") parseAndCompare(t, "OPTION_A: 1", "OPTION_A", "1")
//parses yaml values with equal signs
parseAndCompare(t, "OPTION_A: Foo=bar", "OPTION_A", "Foo=bar")
// parses non-yaml options with colons
parseAndCompare(t, "OPTION_A=1:B", "OPTION_A", "1:B")
// parses export keyword // parses export keyword
parseAndCompare(t, "export OPTION_A=2", "OPTION_A", "2") parseAndCompare(t, "export OPTION_A=2", "OPTION_A", "2")
parseAndCompare(t, `export OPTION_B='\n'`, "OPTION_B", "\n") parseAndCompare(t, `export OPTION_B='\n'`, "OPTION_B", "\n")