Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update apache_conf regular expression to exclude whitespace. #2416

Merged
merged 4 commits into from Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/resources/apache_conf.rb
Expand Up @@ -78,10 +78,17 @@ def read_content
raw_conf = read_file(to_read[0])
@content += raw_conf

# parse include file parameters
# An explaination of the below regular expression.
# Creates two capture groups.
# The first group captures the first group of non-whitespace character
# surrounded whitespace characters.
# The second group contains a conditional with a positive lookahead
# (does the line end with one or more spaces?). If the lookahead succeeds
# a non-greedy capture takes place, if it fails then a greedy capture takes place.
# The regex is terminated by an expression that matches zero or more spaces.
params = SimpleConfig.new(
raw_conf,
assignment_regex: /^\s*(\S+)\s+(.*)\s*$/,
assignment_regex: /^\s*(\S+)\s+((?=.*\s+$).*?|.*)\s*$/,
multiple_values: true,
).params
@params.merge!(params)
Expand Down
1 change: 1 addition & 0 deletions test/unit/mock/files/apache2.conf
@@ -1,5 +1,6 @@
# This is the main Apache server configuration file. It contains comments.
ServerRoot "/etc/apache2"
ServerAlias inspec.test www.inspec.test io.inspec.test

User ${APACHE_RUN_USER}
Include ports.conf
Expand Down
1 change: 1 addition & 0 deletions test/unit/resources/apache_conf_test.rb
Expand Up @@ -12,6 +12,7 @@
_(resource.params).must_be_kind_of Hash
_(resource.content).must_be_kind_of String
_(resource.params('ServerRoot')).must_equal ['"/etc/apache2"']
_(resource.params('ServerAlias')).must_equal ['inspec.test www.inspec.test io.inspec.test']
_(resource.params('Listen').sort).must_equal ['443', '80']
# sourced using a linked file in conf-enabled/
_(resource.params('ServerSignature')).must_equal ['Off']
Expand Down