From e2531ba91bf89cabea97740d63027f7ef4010526 Mon Sep 17 00:00:00 2001 From: Juanadelacuesta <8647634+Juanadelacuesta@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:43:22 +0100 Subject: [PATCH] func: User url rules to scape non alphanumeric values in hcl variables --- api/jobs.go | 6 ++---- api/jobs_test.go | 12 +++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/api/jobs.go b/api/jobs.go index 907f548c434..54344bd357c 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -12,7 +12,6 @@ import ( "net/url" "sort" "strconv" - "strings" "time" "github.com/hashicorp/cronexpr" @@ -324,6 +323,7 @@ func (j *Jobs) Submission(jobID string, version int, q *QueryOptions) (*JobSubmi if err != nil { return nil, nil, err } + return &sub, qm, nil } @@ -1061,9 +1061,7 @@ func (js *JobSubmission) Canonicalize() { // characters to preserve them. This way, when the job gets stopped and // restarted in the UI, variable values will be parsed correctly. for k, v := range js.VariableFlags { - if strings.Contains(v, "\n") { - js.VariableFlags[k] = strings.ReplaceAll(v, "\n", "\\n") - } + js.VariableFlags[k] = url.QueryEscape(v) } } diff --git a/api/jobs_test.go b/api/jobs_test.go index fa68dcf9ae7..1e22fa80ebf 100644 --- a/api/jobs_test.go +++ b/api/jobs_test.go @@ -1503,7 +1503,17 @@ func TestJobs_JobSubmission_Canonicalize(t *testing.T) { VariableFlags: map[string]string{"test": "foo\nbar"}, } js.Canonicalize() - must.Eq(t, js.VariableFlags["test"], "foo\\nbar") + + must.Eq(t, js.VariableFlags["test"], "foo%0Abar") + }) + + t.Run("non-alphabetic chars", func(t *testing.T) { + js := &JobSubmission{ + Source: "abc123", + VariableFlags: map[string]string{"test": `"foo": "bar"`}, + } + js.Canonicalize() + must.Eq(t, js.VariableFlags["test"], "%22foo%22%3A+%22bar%22") }) }