From f378209bf37cdb4abf85a4be3790006f7347a3ca Mon Sep 17 00:00:00 2001 From: Tomas Hozza Date: Wed, 24 Aug 2022 11:00:11 +0200 Subject: [PATCH] Simplify trimming of quotes in `readOSRelease()` Use standard library function to trim surrounding quotes from read values. This makes the code shorter and easier to read. --- internal/common/distro.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/internal/common/distro.go b/internal/common/distro.go index 31fbcc746..e4202c0ad 100644 --- a/internal/common/distro.go +++ b/internal/common/distro.go @@ -60,14 +60,8 @@ func readOSRelease(r io.Reader) (map[string]string, error) { } key := strings.TrimSpace(parts[0]) - value := strings.TrimSpace(parts[1]) - if value[0] == '"' { - if len(value) < 2 || value[len(value)-1] != '"' { - return nil, errors.New("readOSRelease: invalid input") - } - value = value[1 : len(value)-1] - } - + // drop all surrounding whitespace and double-quotes + value := strings.Trim(strings.TrimSpace(parts[1]), "\"") osrelease[key] = value }