dockerversion: simplify escapeStr()

Use a const for the characters to escape, instead of implementing
this as a generic escaping function.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit ff40d2d787)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-06-01 13:38:45 +02:00
parent a27b0381a6
commit 1d45ea52f4
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -69,8 +69,10 @@ func getUserAgentFromContext(ctx context.Context) string {
return upstreamUA
}
const charsToEscape = `();\`
// escapeStr returns s with every rune in charsToEscape escaped by a backslash
func escapeStr(s string, charsToEscape string) string {
func escapeStr(s string) string {
var ret string
for _, currRune := range s {
appended := false
@ -93,7 +95,5 @@ func escapeStr(s string, charsToEscape string) string {
//
// $dockerUA UpstreamClient($upstreamUA)
func insertUpstreamUserAgent(upstreamUA string, dockerUA string) string {
charsToEscape := `();\`
upstreamUAEscaped := escapeStr(upstreamUA, charsToEscape)
return fmt.Sprintf("%s UpstreamClient(%s)", dockerUA, upstreamUAEscaped)
return fmt.Sprintf("%s UpstreamClient(%s)", dockerUA, escapeStr(upstreamUA))
}