Skip to content

Commit 2869087

Browse files
authored
Fix: Handle incoming labels with invalid UTF-8 (#1131)
It's possible that incoming labels will contain invalid UTF-8 characters. This results in a panic. This fix sanitizes the label's string to ensure only valid UTF-8 characters are included, by replacing invalid characters with � (REPLACEMENT CHARACTER) Signed-off-by: Cooper Worobetz <cooper@worobetz.ca>
1 parent 51006ab commit 2869087

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cmd/postgres_exporter/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func dbToString(t interface{}) (string, bool) {
159159
// Try and convert to string
160160
return string(v), true
161161
case string:
162-
return v, true
162+
return strings.ToValidUTF8(v, "�"), true
163163
case bool:
164164
if v {
165165
return "true", true

0 commit comments

Comments
 (0)