Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1493 from joshwget/unquoted-question-marks
Browse files Browse the repository at this point in the history
Allow question marks in unquoted kernel parameters
  • Loading branch information
SvenDowideit committed Jan 8, 2017
2 parents 95a8aa6 + c6232e6 commit 190749f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions config/config_test.go
Expand Up @@ -148,15 +148,15 @@ func TestParseCmdline(t *testing.T) {

assert.Equal(map[interface{}]interface{}{
"rancher": map[interface{}]interface{}{
"strArray": []interface{}{"url:http://192.168.1.100/cloud-config"},
"strArray": []interface{}{"url:http://192.168.1.100/cloud-config?a=b"},
},
}, parseCmdline("rancher.strArray=[\"url:http://192.168.1.100/cloud-config\"]"))
}, parseCmdline("rancher.strArray=[\"url:http://192.168.1.100/cloud-config?a=b\"]"))

assert.Equal(map[interface{}]interface{}{
"rancher": map[interface{}]interface{}{
"strArray": []interface{}{"url:http://192.168.1.100/cloud-config"},
"strArray": []interface{}{"url:http://192.168.1.100/cloud-config?a=b"},
},
}, parseCmdline("rancher.strArray=[url:http://192.168.1.100/cloud-config]"))
}, parseCmdline("rancher.strArray=[url:http://192.168.1.100/cloud-config?a=b]"))
}

func TestGet(t *testing.T) {
Expand Down
9 changes: 6 additions & 3 deletions config/data_funcs.go
Expand Up @@ -116,11 +116,12 @@ func getOrSetVal(args string, data map[interface{}]interface{}, value interface{
return "", tData
}

// Replace newlines and colons with random strings
// Replace newlines, colons, and question marks with random strings
// This is done to avoid YAML treating these as special characters
var (
newlineMagicString = "9XsJcx6dR5EERYCC"
colonMagicString = "V0Rc21pIVknMm2rr"
newlineMagicString = "9XsJcx6dR5EERYCC"
colonMagicString = "V0Rc21pIVknMm2rr"
questionMarkMagicString = "FoPL6JLMAaJqKMJT"
)

func reverseReplacement(result interface{}) interface{} {
Expand All @@ -138,6 +139,7 @@ func reverseReplacement(result interface{}) interface{} {
case string:
val = strings.Replace(val, newlineMagicString, "\n", -1)
val = strings.Replace(val, colonMagicString, ":", -1)
val = strings.Replace(val, questionMarkMagicString, "?", -1)
return val
}

Expand All @@ -147,6 +149,7 @@ func reverseReplacement(result interface{}) interface{} {
func unmarshalOrReturnString(value string) (result interface{}) {
value = strings.Replace(value, "\n", newlineMagicString, -1)
value = strings.Replace(value, ":", colonMagicString, -1)
value = strings.Replace(value, "?", questionMarkMagicString, -1)
if err := yaml.Unmarshal([]byte(value), &result); err != nil {
result = value
}
Expand Down

0 comments on commit 190749f

Please sign in to comment.