ruby3-backward-compatibility 1.1.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +42 -2
- data/Rakefile +14 -2
- data/lib/ruby3_backward_compatibility/compatibility/all.rb +4 -0
- data/lib/ruby3_backward_compatibility/compatibility/dir.rb +5 -0
- data/lib/ruby3_backward_compatibility/compatibility/file.rb +5 -0
- data/lib/ruby3_backward_compatibility/compatibility/fixnum.rb +3 -0
- data/lib/ruby3_backward_compatibility/compatibility/regexp.rb +51 -0
- data/lib/ruby3_backward_compatibility/version.rb +1 -1
- data/lib/ruby3_backward_compatibility.rb +0 -2
- metadata +7 -3
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/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.3.0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.3.0] - 2024-04-16
|
4
|
+
|
5
|
+
- Ruby 3.2+: Add back third argument to Regexp.new, to allow passing "n" to set `Regexp::NOENCODING`.
|
6
|
+
|
7
|
+
## [1.2.0] - 2024-04-10
|
8
|
+
|
9
|
+
- First release with dedicated suport to Ruby 3.3.
|
10
|
+
- Added back `File.exists?` and `Dir.exists?` on Ruby 3.2+.
|
11
|
+
- Added back `Fixnum` as an alias for `Integer`.
|
12
|
+
|
3
13
|
## [1.1.1] - 2022-12-01
|
4
14
|
|
5
15
|
- Gem no longer requires Ruby 3. It will not do anything when used on Ruby 2.x, but you can add it to your Gemfile if you need that for a Ruby migration strategy. (Thanks to @BigAirJosh)
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -71,6 +71,16 @@ This will wrap the given method and convert a hash given as the last argument in
|
|
71
71
|
|
72
72
|
*Note:* In case the method is also defined in a prepended module, you need to put the `extend Ruby3BackwardCompatibility::CallableWithHash` above the `prepend`.
|
73
73
|
|
74
|
+
### Dir
|
75
|
+
|
76
|
+
`Dir.exists?` has been removed in favor of `Dir.exist?`.
|
77
|
+
|
78
|
+
To add `Dir.exists?` as an alias for `Dir.exist?`, use
|
79
|
+
|
80
|
+
```
|
81
|
+
require 'ruby3_backward_compatibility/compatibility/dir'
|
82
|
+
```
|
83
|
+
|
74
84
|
### ERB
|
75
85
|
|
76
86
|
`ERB.new` used to have the signature
|
@@ -91,6 +101,25 @@ To allow both styles, use
|
|
91
101
|
require 'ruby3_backward_compatibility/compatibility/erb'
|
92
102
|
```
|
93
103
|
|
104
|
+
### File
|
105
|
+
|
106
|
+
`File.exists?` has been removed in favor of `File.exist?`.
|
107
|
+
|
108
|
+
To add `File.exists?` as an alias for `File.exist?`, use
|
109
|
+
|
110
|
+
```
|
111
|
+
require 'ruby3_backward_compatibility/compatibility/file'
|
112
|
+
```
|
113
|
+
|
114
|
+
### Fixnum
|
115
|
+
|
116
|
+
`Fixnum` has been an alias for `Integer` for a while, but was removed.
|
117
|
+
|
118
|
+
To add back `Fixnum` as an alias for `Integer`, use
|
119
|
+
|
120
|
+
```
|
121
|
+
require 'ruby3_backward_compatibility/compatibility/fixnum'
|
122
|
+
```
|
94
123
|
|
95
124
|
### I18n
|
96
125
|
|
@@ -113,6 +142,17 @@ To add them back as no-ops, use
|
|
113
142
|
require 'ruby3_backward_compatibility/compatibility/object'
|
114
143
|
```
|
115
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
|
+
```
|
116
156
|
|
117
157
|
### YAML (Psych)
|
118
158
|
|
@@ -130,13 +170,13 @@ Psych version 4 (default for Ruby 3.1) has two changes:
|
|
130
170
|
Psych.safe_load(yaml, permitted_classes: [], permitted_symbols: [], aliases: false, filename: nil)
|
131
171
|
```
|
132
172
|
|
133
|
-
To
|
173
|
+
To allow both styles of calling `Psych.safe_load`, use
|
134
174
|
|
135
175
|
```
|
136
176
|
require 'ruby3_backward_compatibility/compatibility/psych'
|
137
177
|
```
|
138
178
|
|
139
|
-
**Attention:** There has been a very good reason why Psych renamed the `.load` method: You may never use `.load` on any external strings. It is possible to create valid YAML strings that lead to the execution of arbitrary code, so calling `YAML.load` on user input is a major security vulnerability.
|
179
|
+
**Attention:** There has been a very good reason why Psych renamed the `.load` method: You may never use `.load` on any external strings. It is possible to create valid YAML strings that lead to the execution of arbitrary code, so calling `YAML.load` on user input is a major security vulnerability. For that reason, this library does not change the safe behavior of `YAML.load`.
|
140
180
|
|
141
181
|
|
142
182
|
### String
|
data/Rakefile
CHANGED
@@ -3,6 +3,18 @@
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
|
6
|
-
|
6
|
+
ruby2_specs = 'spec/ruby2/**/*_spec.rb'
|
7
|
+
rake_task = RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
if RUBY_VERSION < '3'
|
10
|
+
rake_task.pattern = 'spec/ruby2/**/*_spec.rb'
|
11
|
+
task default: :spec
|
12
|
+
else
|
13
|
+
rake_task.exclude_pattern = 'spec/{ruby2,isolated}/**/*_spec.rb'
|
14
|
+
|
15
|
+
isolated_rake_task = RSpec::Core::RakeTask.new(:isolated_specs)
|
16
|
+
isolated_rake_task.pattern = 'spec/isolated/**/*_spec.rb'
|
17
|
+
|
18
|
+
task default: [:spec, :isolated_specs]
|
19
|
+
end
|
7
20
|
|
8
|
-
task default: :spec
|
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'ruby3_backward_compatibility'
|
2
2
|
|
3
|
+
require 'ruby3_backward_compatibility/compatibility/dir'
|
3
4
|
require 'ruby3_backward_compatibility/compatibility/erb' if defined?(ERB)
|
5
|
+
require 'ruby3_backward_compatibility/compatibility/file'
|
6
|
+
require 'ruby3_backward_compatibility/compatibility/fixnum'
|
4
7
|
require 'ruby3_backward_compatibility/compatibility/i18n' if defined?(I18n)
|
5
8
|
require 'ruby3_backward_compatibility/compatibility/object'
|
6
9
|
require 'ruby3_backward_compatibility/compatibility/psych' if defined?(Psych)
|
10
|
+
require 'ruby3_backward_compatibility/compatibility/regexp'
|
7
11
|
require 'ruby3_backward_compatibility/compatibility/string'
|
8
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:
|
11
|
+
date: 2024-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -45,10 +45,14 @@ files:
|
|
45
45
|
- lib/ruby3_backward_compatibility.rb
|
46
46
|
- lib/ruby3_backward_compatibility/callable_with_hash.rb
|
47
47
|
- lib/ruby3_backward_compatibility/compatibility/all.rb
|
48
|
+
- lib/ruby3_backward_compatibility/compatibility/dir.rb
|
48
49
|
- lib/ruby3_backward_compatibility/compatibility/erb.rb
|
50
|
+
- lib/ruby3_backward_compatibility/compatibility/file.rb
|
51
|
+
- lib/ruby3_backward_compatibility/compatibility/fixnum.rb
|
49
52
|
- lib/ruby3_backward_compatibility/compatibility/i18n.rb
|
50
53
|
- lib/ruby3_backward_compatibility/compatibility/object.rb
|
51
54
|
- lib/ruby3_backward_compatibility/compatibility/psych.rb
|
55
|
+
- lib/ruby3_backward_compatibility/compatibility/regexp.rb
|
52
56
|
- lib/ruby3_backward_compatibility/compatibility/string.rb
|
53
57
|
- lib/ruby3_backward_compatibility/compatibility/uri.rb
|
54
58
|
- lib/ruby3_backward_compatibility/version.rb
|
@@ -75,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
79
|
- !ruby/object:Gem::Version
|
76
80
|
version: '0'
|
77
81
|
requirements: []
|
78
|
-
rubygems_version: 3.3
|
82
|
+
rubygems_version: 3.5.3
|
79
83
|
signing_key:
|
80
84
|
specification_version: 4
|
81
85
|
summary: Backward compatibility for Ruby 3 stdlib
|