[#106341] [Ruby master Bug#18369] users.detect(:name, "Dorian") as shorthand for users.detect { |user| user.name == "Dorian" } — dorianmariefr <noreply@...>
Issue #18369 has been reported by dorianmariefr (Dorian Mari辿).
14 messages
2021/11/30
[#106351] [Ruby master Bug#18371] Release branches (release information in general) — "tenderlovemaking (Aaron Patterson)" <noreply@...>
Issue #18371 has been reported by tenderlovemaking (Aaron Patterson).
7 messages
2021/11/30
[ruby-core:106261] [Ruby master Bug#18141] Marshal load with proc yield objects before they are fully initialized
From:
"usa (Usaku NAKAMURA)" <noreply@...>
Date:
2021-11-24 10:36:11 UTC
List:
ruby-core #106261
Issue #18141 has been updated by usa (Usaku NAKAMURA).
Backport changed from 2.6: REQUIRED, 2.7: REQUIRED, 3.0: DONE to 2.6: REQUIRED, 2.7: DONE, 3.0: DONE
ruby_2_7 419266d44c54c6b75f1e824f060c8b388f7a405b merged revision(s) 89242279e61b023a81c58065c62a82de8829d0b3,529fc204af84f825f98f83c34b004acbaa802615.
----------------------------------------
Bug #18141: Marshal load with proc yield objects before they are fully initialized
https://bugs.ruby-lang.org/issues/18141#change-94881
* Author: byroot (Jean Boussier)
* Status: Closed
* Priority: Normal
* Backport: 2.6: REQUIRED, 2.7: DONE, 3.0: DONE
----------------------------------------
I assume this is a bug because I can't find any spec or test for this behaviour:
Consider the following script:
```ruby
payload = Marshal.dump("foo")
Marshal.load(payload, -> (obj) {
if obj.is_a?(String)
p [obj, obj.encoding]
end
obj
})
p [:final, string, string.encoding]
```
outputs:
```ruby
["foo", #<Encoding:ASCII-8BIT>]
[:final, "foo", #<Encoding:UTF-8>]
```
So `Marshal` call the proc before the string get its encoding assigned, this is because the encoding is stored alongside as a `TYPE_IVAR`. I think in such cases `Marshal` should delay calling the proc until the object is fully restored.
A corollary to this behaviour is that the following code:
```ruby
Marshal.load(payload, :freeze.to_proc)
```
raises with `can't modify frozen String: "foo" (FrozenError)`.
The same happens with any instance variable on `Array` or `Hash`
```ruby
foo = {}
foo.instance_variable_set(:@bar, 42)
payload = Marshal.dump(foo)
object = Marshal.load(payload, ->(obj) {
if obj.is_a?(Hash)
p [obj, obj.instance_variable_get(:@bar)]
obj.freeze
end
obj
})
```
```
[{}, nil]
/tmp/marshal.rb:6:in `load': can't modify frozen Hash: {} (FrozenError)
from /tmp/marshal.rb:6:in `<main>
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>