ruby3-backward-compatibility 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d727adf8f484386c84adf5f03c83b8b8e237d072e9755e34770f4c37c87c3f27
|
4
|
+
data.tar.gz: ccb5329f49247817fbc12f9b72d1a893a57ed53f2c71b7c769d7c397d2e074ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c92cb15cc48cf8c4c78c73ebad18e980a73cdd889993d68de2a4873666a1f81a6a2715140bddb8a14f8e8b6cfd3270eb7481d9bb33c74c702495606d623ca300
|
7
|
+
data.tar.gz: b8c56baf3948241066277afc1289d9421df3cb8854a11b38f35b5cd18155a51180f1935418e8ed294b82900e14a8e9d33d48452fe226c3eea8be0d6afc237470
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -142,6 +142,17 @@ To add them back as no-ops, use
|
|
142
142
|
require 'ruby3_backward_compatibility/compatibility/object'
|
143
143
|
```
|
144
144
|
|
145
|
+
### Regexp (Ruby 3.2+)
|
146
|
+
|
147
|
+
It was possible to instantiate a Regexp with `Regexp.new('foo', Regexp::IGNORECASE, 'n')`. The last argument used to indicate the encoding in Ruby 1.8. Up to Ruby 3.2 an argument of "n" or "N" indicated a regexp that ignores encoding (same as the Regexp::NOENCODING flag).
|
148
|
+
|
149
|
+
In Ruby 3 this raises an `ArgumentError`.
|
150
|
+
|
151
|
+
To bring back the old behavior, use
|
152
|
+
|
153
|
+
```
|
154
|
+
require 'ruby3_backward_compatibility/compatibility/regexp'
|
155
|
+
```
|
145
156
|
|
146
157
|
### YAML (Psych)
|
147
158
|
|
@@ -7,5 +7,6 @@ require 'ruby3_backward_compatibility/compatibility/fixnum'
|
|
7
7
|
require 'ruby3_backward_compatibility/compatibility/i18n' if defined?(I18n)
|
8
8
|
require 'ruby3_backward_compatibility/compatibility/object'
|
9
9
|
require 'ruby3_backward_compatibility/compatibility/psych' if defined?(Psych)
|
10
|
+
require 'ruby3_backward_compatibility/compatibility/regexp'
|
10
11
|
require 'ruby3_backward_compatibility/compatibility/string'
|
11
12
|
require 'ruby3_backward_compatibility/compatibility/uri' if defined?(URI)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
if RUBY_VERSION >= '3.2'
|
2
|
+
# on 3.2 exactly, we get deprecation errors
|
3
|
+
# however, this is somewhat hard to fix, since 3.2 added some different ways to pass "options" that we do not want to rebuild
|
4
|
+
|
5
|
+
module Ruby3BackwardCompatibility
|
6
|
+
module RegexpCompatibility
|
7
|
+
LEGITIMATE_FLAGS = /\A[mix]+\z/
|
8
|
+
|
9
|
+
def self.prepended(by)
|
10
|
+
by.singleton_class.prepend ClassMethods
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def new(regexp_or_string, options = NOT_GIVEN, n_flag = NOT_GIVEN, **kwargs)
|
15
|
+
if options == NOT_GIVEN
|
16
|
+
super(regexp_or_string, **kwargs)
|
17
|
+
elsif n_flag == 'n' || n_flag == 'N'
|
18
|
+
unless options.is_a?(Integer)
|
19
|
+
if RUBY_VERSION < '3.3' && options.is_a?(String) && options =~ LEGITIMATE_FLAGS
|
20
|
+
# on Ruby 3.2 we can legitimately have options "mix" treated as flags, so parse them
|
21
|
+
# on Ruby 3.3 this would never have been legitimate, since a third argument would not have been allowed
|
22
|
+
new_options = 0
|
23
|
+
new_options |= Regexp::MULTILINE if options.include?('m')
|
24
|
+
new_options |= Regexp::IGNORECASE if options.include?('i')
|
25
|
+
new_options |= Regexp::EXTENDED if options.include?('x')
|
26
|
+
options = new_options
|
27
|
+
else
|
28
|
+
# on all other Ruby, truish is IGNORECASE
|
29
|
+
options = options ? Regexp::IGNORECASE : 0
|
30
|
+
end
|
31
|
+
end
|
32
|
+
super(regexp_or_string, options | Regexp::NOENCODING, **kwargs)
|
33
|
+
elsif options.is_a?(String)
|
34
|
+
if options =~ LEGITIMATE_FLAGS && n_flag == NOT_GIVEN
|
35
|
+
# this (like any trueish value) would have been "ignore case" in Ruby < 3.2, but now is not
|
36
|
+
# we have to assume this is Ruby 3.2 syntax
|
37
|
+
super(regexp_or_string, options, **kwargs)
|
38
|
+
else
|
39
|
+
# this crashes on Ruby 3.2, so assume it is < 3.2 syntax
|
40
|
+
super(regexp_or_string, true, **kwargs)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
super(regexp_or_string, options, **kwargs)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Regexp.prepend Ruby3BackwardCompatibility::RegexpCompatibility
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby3-backward-compatibility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Kraze
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- lib/ruby3_backward_compatibility/compatibility/i18n.rb
|
53
53
|
- lib/ruby3_backward_compatibility/compatibility/object.rb
|
54
54
|
- lib/ruby3_backward_compatibility/compatibility/psych.rb
|
55
|
+
- lib/ruby3_backward_compatibility/compatibility/regexp.rb
|
55
56
|
- lib/ruby3_backward_compatibility/compatibility/string.rb
|
56
57
|
- lib/ruby3_backward_compatibility/compatibility/uri.rb
|
57
58
|
- lib/ruby3_backward_compatibility/version.rb
|