mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
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>
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user