Skip to content

Commit

Permalink
Update the regular expression to include a conditional with positive
Browse files Browse the repository at this point in the history
lookahead that checks if the line ends with one or more spaces. If the
lookahead succeeds we non-greedily capture, and when it fails we
greedily capture.

Signed-off-by: Miah Johnson <miah@chia-pet.org>
  • Loading branch information
miah committed Dec 21, 2017
1 parent 709110f commit 02d054b
Showing 1 changed file with 9 additions and 2 deletions.
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

0 comments on commit 02d054b

Please sign in to comment.