From 6e21c9f77f362317a9e338e2e72b1bc2ec0262a6 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Fri, 2 Feb 2024 14:58:49 +1100 Subject: [PATCH] Need to escape single quotes in bash, updated docs #1932 --- pkg/yqlib/doc/usage/recipes.md | 8 ++++---- pkg/yqlib/operators_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/yqlib/doc/usage/recipes.md b/pkg/yqlib/doc/usage/recipes.md index 6316df32..9e75c425 100644 --- a/pkg/yqlib/doc/usage/recipes.md +++ b/pkg/yqlib/doc/usage/recipes.md @@ -168,8 +168,8 @@ fruit: then ```bash yq '.[] |( - ( select(kind == "scalar") | key + "='" + . + "'"), - ( select(kind == "seq") | key + "=(" + (map("'" + . + "'") | join(",")) + ")") + ( select(kind == "scalar") | key + "='\''" + . + "'\''"), + ( select(kind == "seq") | key + "=(" + (map("'\''" + . + "'\''") | join(",")) + ")") )' sample.yml ``` will output @@ -203,8 +203,8 @@ deep: then ```bash yq '.. |( - ( select(kind == "scalar" and parent | kind != "seq") | (path | join("_")) + "='" + . + "'"), - ( select(kind == "seq") | (path | join("_")) + "=(" + (map("'" + . + "'") | join(",")) + ")") + ( select(kind == "scalar" and parent | kind != "seq") | (path | join("_")) + "='\''" + . + "'\''"), + ( select(kind == "seq") | (path | join("_")) + "=(" + (map("'\''" + . + "'\''") | join(",")) + ")") )' sample.yml ``` will output diff --git a/pkg/yqlib/operators_test.go b/pkg/yqlib/operators_test.go index 9de2bbc4..01562fd8 100644 --- a/pkg/yqlib/operators_test.go +++ b/pkg/yqlib/operators_test.go @@ -317,7 +317,7 @@ func documentInput(w *bufio.Writer, s expressionScenario) (string, string) { writeOrPanic(w, "then\n") if s.expression != "" { - writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v'%v' %v\n```\n", envCommand, command, s.expression, files)) + writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v'%v' %v\n```\n", envCommand, command, strings.ReplaceAll(s.expression, "'", `'\''`), files)) } else { writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v%v\n```\n", envCommand, command, files)) }