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

Respect Regexp.compile method signature #9351

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions lib/puppet/functions/regsubst.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@
# - *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']]
# 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
# Deprecated and ignored parameter, only here for compatibility.
# @return [Array[String], String] The result of the substitution. Result type is the same as for the target parameter.
# @deprecated
# This method has the optional encoding parameter, which is ignored.
# @example Get the third octet from the node's IP address:
# ```puppet
# $i3 = regsubst($ipaddress,'^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$','\\3')
Expand Down Expand Up @@ -56,13 +53,6 @@
# - *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']]
# 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 @@ -76,6 +66,13 @@
end

def regsubst_string(target, pattern, replacement, flags = nil, encoding = nil)
if encoding
Puppet.warn_once(
'deprecations', 'regsubst_function_encoding',
_("The regsubst() function's encoding argument has been ignored since Ruby 1.9 and will be removed in a future release")
)
end

re_flags = 0
operation = :sub
unless flags.nil?
Expand All @@ -88,7 +85,7 @@ def regsubst_string(target, pattern, replacement, flags = nil, encoding = nil)
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