From 5edcae13b3ed82601abf5cb679797dfde3e501c2 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 16 Jul 2020 17:19:57 -0400 Subject: [PATCH 1/2] distro: remove unwanted chars from os distro files Signed-off-by: Alfredo Deza --- imgbom/distro/identify.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgbom/distro/identify.go b/imgbom/distro/identify.go index 07589962b..7070ce4ca 100644 --- a/imgbom/distro/identify.go +++ b/imgbom/distro/identify.go @@ -92,9 +92,9 @@ func parseOsRelease(contents string) *Distro { switch prefix { case "ID": - id = value + id = strings.TrimSpace(value) case "VERSION_ID": - vers = value + vers = strings.TrimSpace(value) } } From fb6bc116e05e3b3487bd60634624771d71299568 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 16 Jul 2020 17:20:30 -0400 Subject: [PATCH 2/2] tests: verify carriage returns are parsed in distro files Signed-off-by: Alfredo Deza --- imgbom/distro/identify_test.go | 5 +++++ imgbom/distro/test-fixtures/unprintable | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 imgbom/distro/test-fixtures/unprintable diff --git a/imgbom/distro/identify_test.go b/imgbom/distro/identify_test.go index b21899dac..671f012a3 100644 --- a/imgbom/distro/identify_test.go +++ b/imgbom/distro/identify_test.go @@ -34,6 +34,11 @@ func TestParseOsRelease(t *testing.T) { name: "redhat", RawVersion: "8.1", }, + { + fixture: "test-fixtures/unprintable", + name: "debian", + RawVersion: "8", + }, } for _, test := range tests { diff --git a/imgbom/distro/test-fixtures/unprintable b/imgbom/distro/test-fixtures/unprintable new file mode 100644 index 000000000..fa9c6b547 --- /dev/null +++ b/imgbom/distro/test-fixtures/unprintable @@ -0,0 +1,8 @@ +PRETTY_NAME="Debian GNU/Linux 8 (jessie)" +NAME="Debian GNU/Linux" +VERSION_ID="8" +VERSION="8 (jessie)" +ID=debian +HOME_URL="http://www.debian.org/" +SUPPORT_URL="http://www.debian.org/support" +BUG_REPORT_URL="https://bugs.debian.org/"