Skip to content

Commit f4fa383

Browse files
committed
Respect Regexp.compile method signature
Since Ruby 1.9 the encoding argument to Regexp.compile has been ignored and has been removed since. Starting Ruby 3.2 there is a new third positional argument for the timeout. This PR deprecates the old method with encoding and stops passing the argument, making it a dead parameter.
1 parent ed4eee5 commit f4fa383

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

lib/puppet/functions/regsubst.rb

+11-14
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
2020
# - *M* Multiline regexps
2121
# - *G* Global replacement; all occurrences of the regexp in each target string will be replaced. Without this, only the first occurrence will be replaced.
2222
# @param encoding [Enum['N','E','S','U']]
23-
# Optional. How to handle multibyte characters when compiling the regexp (must not be used when pattern is a
24-
# precompiled regexp). A single-character string with the following values:
25-
# - *N* None
26-
# - *E* EUC
27-
# - *S* SJIS
28-
# - *U* UTF-8
23+
# Deprecated and ignored parameter, only here for compatibility.
2924
# @return [Array[String], String] The result of the substitution. Result type is the same as for the target parameter.
25+
# @deprecated
26+
# This method has the optional encoding parameter, which is ignored.
3027
# @example Get the third octet from the node's IP address:
3128
# ```puppet
3229
# $i3 = regsubst($ipaddress,'^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$','\\3')
@@ -56,13 +53,6 @@
5653
# - *I* Ignore case in regexps
5754
# - *M* Multiline regexps
5855
# - *G* Global replacement; all occurrences of the regexp in each target string will be replaced. Without this, only the first occurrence will be replaced.
59-
# @param encoding [Enum['N','E','S','U']]
60-
# Optional. How to handle multibyte characters when compiling the regexp (must not be used when pattern is a
61-
# precompiled regexp). A single-character string with the following values:
62-
# - *N* None
63-
# - *E* EUC
64-
# - *S* SJIS
65-
# - *U* UTF-8
6656
# @return [Array[String], String] The result of the substitution. Result type is the same as for the target parameter.
6757
# @example Put angle brackets around each octet in the node's IP address:
6858
# ```puppet
@@ -76,6 +66,13 @@
7666
end
7767

7868
def regsubst_string(target, pattern, replacement, flags = nil, encoding = nil)
69+
if encoding
70+
Puppet.warn_once(
71+
'deprecations', 'regsubst_function_encoding',
72+
_("The regsubst() function's encoding argument has been ignored since Ruby 1.9 and will be removed in a future release")
73+
)
74+
end
75+
7976
re_flags = 0
8077
operation = :sub
8178
unless flags.nil?
@@ -88,7 +85,7 @@ def regsubst_string(target, pattern, replacement, flags = nil, encoding = nil)
8885
end
8986
end
9087
end
91-
inner_regsubst(target, Regexp.compile(pattern, re_flags, encoding), replacement, operation)
88+
inner_regsubst(target, Regexp.compile(pattern, re_flags), replacement, operation)
9289
end
9390

9491
def regsubst_regexp(target, pattern, replacement, flags = nil)

0 commit comments

Comments
 (0)