Skip to content

Commit 30325d0

Browse files
fxpiresAriaXLi
authored andcommitted
(FACT-3151) Ensure /etc/os-release can contain comments without raising
Comments are allowed in the /etc/os-release files (see this link for more information: https://www.man7.org/linux/man-pages/man5/os-release.5.html). This commit enables comments in /etc/os-releases files without raising an exception and adds a spec test to ensure Facter is behaving as expected. Fabiano Pires (fxpires) wrote the commit that allows comments in /etc/os-release files without raising an exception. Previously, Facter would raise an exception if there was a comment in the /etc/os-release files. Co-authored by: Fabiano Pires <[email protected]>
1 parent 2a2e4de commit 30325d0

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

lib/facter/resolvers/os_release.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def read_and_parse_os_release_file
4949

5050
pairs = []
5151
content.each do |line|
52-
pairs << line.strip.delete('"').split('=', 2)
52+
pairs << line.strip.delete('"').split('=', 2) unless line.start_with?('#')
5353
end
5454

5555
pairs

spec/facter/resolvers/os_release_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@
5656
end
5757
end
5858

59+
context 'when /etc/os-release file has comment' do
60+
let(:os_release_content) { load_fixture('os_release_redhat_linux_with_comment').readlines }
61+
62+
it 'does not raise an exception' do
63+
expect { Facter::Resolvers::OsRelease.resolve(:name) }.not_to raise_error
64+
end
65+
end
66+
5967
context 'when on Debian' do
6068
let(:os_release_content) { load_fixture('os_release_debian').readlines }
6169

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This is a comment
2+
NAME="Red Hat Enterprise Linux"
3+
VERSION="8.6 (Ootpa)"
4+
ID="rhel"
5+
ID_LIKE="fedora"
6+
VERSION_ID="8.6"
7+
PLATFORM_ID="platform:el8"
8+
PRETTY_NAME="Red Hat Enterprise Linux 8.6 (Ootpa)"
9+
ANSI_COLOR="0;31"
10+
CPE_NAME="cpe:/o:redhat:enterprise_linux:8::baseos"
11+
HOME_URL="https://www.redhat.com/"
12+
DOCUMENTATION_URL="https://access.redhat.com/documentation/red_hat_enterprise_linux/8/"
13+
BUG_REPORT_URL="https://bugzilla.redhat.com/"
14+
15+
# Whoa, this is another comment!
16+
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
17+
REDHAT_BUGZILLA_PRODUCT_VERSION=8.6
18+
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
19+
REDHAT_SUPPORT_PRODUCT_VERSION="8.6"

0 commit comments

Comments
 (0)