プロジェクト

全般

プロフィール

Vote #81714

完了

Psych 4: Psych::DisallowedClass exception when unserializing a setting value

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Gems support_45
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
45
version_id:
171
issue_org_id:
36226
author_id:
332
assigned_to_id:
332
comments:
7
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

Psych 4.0 uses @safe_load@ by default (see https://github.com/ruby/psych/pull/487). Due to this change, @Setting#value@ may raise Psych::DisallowedClass exception.

$ echo gem "'psych', '~> 4.0.0'" >> Gemfile.local
$ bundle install
$ bin/rails test test/functional/settings_controller_test.rb 
Run options: --seed 45283

# Running:

...................E

Error:
SettingsControllerTest#test_post_plugin_settings:
Psych::DisallowedClass: Tried to load unspecified class: ActiveSupport::HashWithIndifferentAccess
    app/models/setting.rb:109:in `value'
    app/models/setting.rb:131:in `[]='
    app/models/setting.rb:326:in `plugin_foo='
    app/controllers/settings_controller.rb:73:in `plugin'
    lib/redmine/sudo_mode.rb:61:in `sudo_mode'
    test/functional/settings_controller_test.rb:244:in `test_post_plugin_settings'


rails test test/functional/settings_controller_test.rb:237

journals

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
The following patch fixes the issue.

<pre><code class="diff">
diff --git a/app/models/setting.rb b/app/models/setting.rb
index dfa054028..2b6a7a1ff 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -106,7 +106,8 @@ class Setting < ActiveRecord::Base
v = read_attribute(:value)
# Unserialize serialized settings
if available_settings[name]['serialized'] && v.is_a?(String)
- v = YAML::load(v)
+ # YAML.load is equivalent to YAML.safe_load in Pysch 4
+ v = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(v) : YAML.load(v)
v = force_utf8_strings(v)
end
v = v.to_sym if available_settings[name]['format'] == 'symbol' && !v.blank?
</code></pre>
--------------------------------------------------------------------------------
Committed the fix.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

relates,Closed,36205,Ruby 3.1 support
duplicates,Closed,36584,Error on creating custom fields using Ruby version 2.7.2

Admin Redmine さんが約4年前に更新

  • カテゴリGems support_45 にセット
  • 対象バージョン4.1.6_171 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0