Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pkg/utils/parse_arf_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,14 @@ func toArrayByComma(format string) []string {
return strings.Split(format, ",")
}

func urlEncode(s string) string {
return url.PathEscape(s)
}

func unescapeNewlines(s string) string {
return strings.ReplaceAll(s, "\\n", "\n")
}

// This function will take original remediation content, and a list of all values found in the configMap
// It will processed and substitue the value in remediation content, and return processed Remediation content
// The return will be Processed-Remdiation Content, Value-Used List, Un-Set List, and err if possible
Expand Down Expand Up @@ -1013,8 +1021,11 @@ func processContent(preProcessedContent string, resultValues map[string]string)
var valuesUsedList []string
var valuesMissingList []string
var valuesParsedList []string
t, err := template.New("").Option("missingkey=zero").Funcs(template.FuncMap{"toArrayByComma": toArrayByComma}).
Parse(preProcessedContent)
t, err := template.New("").Option("missingkey=zero").Funcs(template.FuncMap{
"toArrayByComma": toArrayByComma,
"urlencode": urlEncode,
"unescapeNewlines": unescapeNewlines,
}).Parse(preProcessedContent)
if err != nil {
return preProcessedContent, valuesUsedList, valuesMissingList, errors.Wrap(err, "wrongly formatted remediation context: ") //Error creating template // Wrongly formatted remediation context
}
Expand Down
31 changes: 31 additions & 0 deletions pkg/utils/parse_arf_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,37 @@ Server 3.fedora.pool.ntp.org`
})
})

Describe("Testing unescapeNewlines function", func() {
Context("When given strings with literal newline escape sequences", func() {
It("Should convert single newline", func() {
input := "line1\\nline2"
expected := "line1\nline2"
result := unescapeNewlines(input)
Expect(result).To(Equal(expected))
})

It("Should convert multiple newlines", func() {
input := "line1\\nline2\\n\\nline3"
expected := "line1\nline2\n\nline3"
result := unescapeNewlines(input)
Expect(result).To(Equal(expected))
})

It("Should handle strings without newlines", func() {
input := "single line"
expected := "single line"
result := unescapeNewlines(input)
Expect(result).To(Equal(expected))
})

It("Should handle empty string", func() {
input := ""
expected := ""
result := unescapeNewlines(input)
Expect(result).To(Equal(expected))
})
})
})
})

// printUniquePaths prints all unique paths within an XML document, starting from a given node.
Expand Down
Loading