From c873b1c82e6cba50d11881ff1fc43dd74019a885 Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Fri, 15 Dec 2017 12:51:19 +0100 Subject: [PATCH] Allow to escape newlines and tabs in --set Fixes #3251 --- docs/using_helm.md | 6 ++++++ pkg/strvals/parser.go | 9 +++++++++ pkg/strvals/parser_test.go | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/docs/using_helm.md b/docs/using_helm.md index d2e1768a8..e3d1004a2 100755 --- a/docs/using_helm.md +++ b/docs/using_helm.md @@ -300,6 +300,12 @@ nodeSelector: kubernetes.io/role: master ``` +Other escape sequences are supported: +- ```\\n``` +- ```\\r``` +- ```\\t``` +- any unsupported sequence will keep the following character + Deeply nested data structures can be difficult to express using `--set`. Chart designers are encouraged to consider the `--set` usage when designing the format of a `values.yaml` file. diff --git a/pkg/strvals/parser.go b/pkg/strvals/parser.go index 8e97b4d44..de666c022 100644 --- a/pkg/strvals/parser.go +++ b/pkg/strvals/parser.go @@ -286,6 +286,15 @@ func runesUntil(in io.RuneReader, stop map[rune]bool) ([]rune, rune, error) { if e != nil { return v, next, e } + switch next { + case 'n': + next = '\n' + case 'r': + next = '\r' + case 't': + next = '\t' + } + v = append(v, next) default: v = append(v, r) diff --git a/pkg/strvals/parser_test.go b/pkg/strvals/parser_test.go index a3f6e4207..a8124968d 100644 --- a/pkg/strvals/parser_test.go +++ b/pkg/strvals/parser_test.go @@ -255,6 +255,10 @@ func TestParseSet(t *testing.T) { str: "nested[1][1]=1", expect: map[string]interface{}{"nested": []interface{}{nil, []interface{}{nil, 1}}}, }, + { + str: "escapes=hello\\n\\tworld", + expect: map[string]interface{}{"escapes": "hello\n\tworld"}, + }, } for _, tt := range tests {