mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-09-16 07:09:30 +00:00
Fix parsing cmdline when keys have a dash (#73)
* Fix parsing cmdline when keys have a dash If a key has a dash we need to add quotes to it before parsing it with gojq, otherwise it will fail AND the full cmdline will not be parsed! Signed-off-by: Itxaka <itxaka@kairos.io> * Actualizar bootcmdline_test.go --------- Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
@@ -3,10 +3,10 @@ package unstructured
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/itchyny/gojq"
|
||||
"gopkg.in/yaml.v3"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func YAMLHasKey(query string, content []byte) (bool, error) {
|
||||
@@ -109,12 +109,22 @@ func ToYAML(v map[string]interface{}) ([]byte, error) {
|
||||
var errs error
|
||||
|
||||
for k, value := range v {
|
||||
tmpl := ".%s=\"%s\""
|
||||
prefix := "."
|
||||
equal := "="
|
||||
tmplKey := "%s"
|
||||
tmplValue := "\"%s\""
|
||||
|
||||
// If key has a dash we need to add quotes to it to avoid failure parsing ut
|
||||
if strings.Contains(k, "-") {
|
||||
tmplKey = "\"%s\""
|
||||
}
|
||||
|
||||
// support boolean types
|
||||
if value == "true" || value == "false" {
|
||||
tmpl = ".%s=%s"
|
||||
tmplValue = "%s"
|
||||
}
|
||||
newData, err := jq(fmt.Sprintf(tmpl, k, value), data)
|
||||
finalTemplate := prefix + tmplKey + equal + tmplValue
|
||||
newData, err := jq(fmt.Sprintf(finalTemplate, k, value), data)
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
continue
|
||||
|
Reference in New Issue
Block a user