From 5a954a51a00852fb63fcbb2fb8c5d9a45def9cd6 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Sat, 18 May 2024 18:40:01 +0200 Subject: [PATCH] Respect Regexp.compile method signature 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. --- lib/puppet/functions/regsubst.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/puppet/functions/regsubst.rb b/lib/puppet/functions/regsubst.rb index af27fb8777a..12352a355ec 100644 --- a/lib/puppet/functions/regsubst.rb +++ b/lib/puppet/functions/regsubst.rb @@ -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 @@ -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)