Skip to content

Commit 94081b2

Browse files
committed
MAJOR: escape backslash character in host name
haproxy runtime socket needs that the backslash escape character in host name be escaped too.
1 parent afeb969 commit 94081b2

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

k8s/gate/haproxy/routes-maps.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package haproxy
1717
import (
1818
"context"
1919
"log/slog"
20+
"regexp"
2021

2122
"github.com/haproxytech/haproxy-unified-gateway/k8s/gate/haproxy/storage/maps"
2223
"github.com/haproxytech/haproxy-unified-gateway/k8s/gate/logging"
@@ -25,6 +26,8 @@ import (
2526
"github.com/haproxytech/haproxy-unified-gateway/k8s/gate/utils"
2627
)
2728

29+
var re = regexp.MustCompile(`\\+`)
30+
2831
// ErrMapRuntimeUpdate is an error type for runtime map update failures
2932
type ErrMapRuntimeUpdate struct {
3033
Err error
@@ -194,8 +197,6 @@ func (b *RouteMgrImpl) writeMaps() error {
194197

195198
// runtimeMapSync updates the runtime maps through runtime API
196199
func (b *RouteMgrImpl) runtimeMapSync() error {
197-
b.topManager.logger.LogAttrs(context.Background(), slog.LevelInfo, "map [runtime] updates")
198-
199200
mapsStorage := b.topManager.params.mapsStorageEx
200201
runtimeClient := b.topManager.haproxyClient.RuntimeClient()
201202

@@ -218,7 +219,7 @@ func (b *RouteMgrImpl) runtimeMapSync() error {
218219
continue
219220
}
220221
for entryKey, entryValue := range mapData.Entries {
221-
key := entryKey.Hostname
222+
key := escapeSlashForRuntime(entryKey.Hostname)
222223
if entryKey.Path != "" {
223224
key += entryKey.Path
224225
}
@@ -287,3 +288,9 @@ func (b *RouteMgrImpl) getMapID(fullPath string) (string, error) {
287288
}
288289
return "", nil
289290
}
291+
292+
func escapeSlashForRuntime(key string) string {
293+
return re.ReplaceAllStringFunc(key, func(s string) string {
294+
return `\` + s
295+
})
296+
}

0 commit comments

Comments
 (0)