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>
| ... | ... |
@@ -69,8 +69,10 @@ func getUserAgentFromContext(ctx context.Context) string {
|
| 69 | 69 |
return upstreamUA |
| 70 | 70 |
} |
| 71 | 71 |
|
| 72 |
+const charsToEscape = `();\` |
|
| 73 |
+ |
|
| 72 | 74 |
// escapeStr returns s with every rune in charsToEscape escaped by a backslash |
| 73 |
-func escapeStr(s string, charsToEscape string) string {
|
|
| 75 |
+func escapeStr(s string) string {
|
|
| 74 | 76 |
var ret string |
| 75 | 77 |
for _, currRune := range s {
|
| 76 | 78 |
appended := false |
| ... | ... |
@@ -93,7 +95,5 @@ func escapeStr(s string, charsToEscape string) string {
|
| 93 | 93 |
// |
| 94 | 94 |
// $dockerUA UpstreamClient($upstreamUA) |
| 95 | 95 |
func insertUpstreamUserAgent(upstreamUA string, dockerUA string) string {
|
| 96 |
- charsToEscape := `();\` |
|
| 97 |
- upstreamUAEscaped := escapeStr(upstreamUA, charsToEscape) |
|
| 98 |
- return fmt.Sprintf("%s UpstreamClient(%s)", dockerUA, upstreamUAEscaped)
|
|
| 96 |
+ return fmt.Sprintf("%s UpstreamClient(%s)", dockerUA, escapeStr(upstreamUA))
|
|
| 99 | 97 |
} |