Skip to content

Commit

Permalink
Respect Regexp.compile method signature
Browse files Browse the repository at this point in the history
As far as I can tell, Regexp.compile has never accepted a third
parameter to Regexp.compile until Ruby 3.2. There it actually is a
timeout parameter. In older versions it was discarded as an invalid
input. It's unclear to me if this parameter ever worked in the first
place.

This PR attemps to still make it work as it was originally intended, but
it's unclear what the original goal even was.
  • Loading branch information
ekohl committed May 18, 2024
1 parent 779595a commit 5a954a5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/puppet/functions/regsubst.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,10 @@
# - *I* Ignore case in regexps
# - *M* Multiline regexps
# - *G* Global replacement; all occurrences of the regexp in each target string will be replaced. Without this, only the first occurrence will be replaced.
# @param encoding [Enum['N','E','S','U']]
# @param encoding [Optional[Enum['N']]
# Optional. How to handle multibyte characters when compiling the regexp (must not be used when pattern is a
# precompiled regexp). A single-character string with the following values:
# - *N* None
# - *E* EUC
# - *S* SJIS
# - *U* UTF-8
# @return [Array[String], String] The result of the substitution. Result type is the same as for the target parameter.
# @example Put angle brackets around each octet in the node's IP address:
# ```puppet
Expand All @@ -85,10 +82,11 @@ def regsubst_string(target, pattern, replacement, flags = nil, encoding = nil)
when 'E' then re_flags |= Regexp::EXTENDED
when 'I' then re_flags |= Regexp::IGNORECASE
when 'M' then re_flags |= Regexp::MULTILINE
when 'N' then re_flags |= Regexp::NOENCODING
end
end
end
inner_regsubst(target, Regexp.compile(pattern, re_flags, encoding), replacement, operation)
inner_regsubst(target, Regexp.compile(pattern, re_flags), replacement, operation)
end

def regsubst_regexp(target, pattern, replacement, flags = nil)
Expand Down

0 comments on commit 5a954a5

Please sign in to comment.