Skip to content

Commit 99af076

Browse files
cbliardoliverguenther
authored andcommitted
[#42226] Psych::DisallowedClass: Tried to load unspecified class: URI::Generic while upgrading from 12.01 to 12.10
https://community.openproject.org/work_packages/42226 properly deserialize setting hash value having a URI::Generic inside
1 parent a291d98 commit 99af076

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

app/models/setting.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,20 @@ def self.deserialize(name, value)
325325
definition = Settings::Definition[name]
326326

327327
if definition.serialized? && value.is_a?(String)
328-
YAML::safe_load(value, permitted_classes: [Symbol, ActiveSupport::HashWithIndifferentAccess, Date, Time])
329-
.tap { |maybe_hash| maybe_hash.try(:deep_stringify_keys!) }
328+
YAML::safe_load(value, permitted_classes: [Symbol, ActiveSupport::HashWithIndifferentAccess, Date, Time, URI::Generic])
329+
.tap { |maybe_hash| normalize_hash!(maybe_hash) if maybe_hash.is_a?(Hash) }
330330
elsif value != '' && !value.nil?
331331
read_formatted_setting(value, definition.format)
332332
else
333333
definition.format == :string ? value : nil
334334
end
335335
end
336336

337+
def self.normalize_hash!(hash)
338+
hash.deep_stringify_keys!
339+
hash.deep_transform_values! { |v| v.is_a?(URI::Generic) ? v.to_s : v }
340+
end
341+
337342
def self.read_formatted_setting(value, format)
338343
case format
339344
when :boolean

docs/installation-and-operations/misc/migration/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ You can simply look through the installer.dat and change those values you need.
4444

4545
**The conf.d folder**
4646

47-
Additional environment, either generated from the wizard or entered by you through `openproject config:set` is written to `/etc/openproject/conf.d/{server,database,other}`. Also look through those and check which contain relevant values for your new installation.
47+
Additional environment, either generated from the wizard or entered by you through `openproject config:set` is written to `/etc/openproject/conf.d/{server,database,other}`. Also look through those and check which contain relevant values for your new installation.
4848

4949
### PostgreSQL database
5050

@@ -68,7 +68,7 @@ pg_restore -h <dbhost> -u <dbuser> -W --dbname <dbname> --clean postgresql-dump-
6868

6969
### Attachments
7070

71-
Your storage path can be shown on the old installation can be shown using the following command:
71+
Your storage path on the old installation can be shown using the following command:
7272

7373
```
7474
openproject config:get ATTACHMENTS_STORAGE_PATH
@@ -83,7 +83,7 @@ Simply extract your attachments dump into that folder with `tar -vxfz <dump>.tar
8383

8484
For repositories, the same approach applies as for the attachments:
8585

86-
Your SVN and Git storage paths can be shown on the old installation can be shown using the following command:
86+
Your SVN and Git storage paths on the old installation can be shown using the following command:
8787

8888
```
8989
# Subversion

lib/tasks/packager.rake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ namespace :packager do
115115
if svn_path.present?
116116
# migrate previous repositories with reposman to managed
117117
Rake::Task['scm:migrate:managed'].invoke("file://#{svn_path}")
118-
checkout_data['subversion'] = { 'enabled' => 1, 'base_url' => URI.join(base_url, prefix, 'svn') }
118+
checkout_data['subversion'] = { 'enabled' => 1, 'base_url' => URI.join(base_url, prefix, 'svn').to_s }
119119
end
120120

121121
if git_path.present?
122-
checkout_data['git'] = { 'enabled' => 1, 'base_url' => URI.join(base_url, prefix, 'git') }
122+
checkout_data['git'] = { 'enabled' => 1, 'base_url' => URI.join(base_url, prefix, 'git').to_s }
123123
end
124124

125125
Setting.repository_checkout_data = checkout_data

spec/models/setting_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,28 @@
303303
end
304304
end
305305

306+
describe 'serialized hash settings with URI::Generic inside it' do
307+
before do
308+
setting = described_class.create!(name: 'repository_checkout_data')
309+
setting.update_columns(
310+
value: {
311+
git: { enabled: 1, base_url: URI::Generic.build(scheme: 'https', host: 'git.example.com', path: '/public') },
312+
subversion: { enabled: 0 }
313+
}.to_yaml
314+
)
315+
end
316+
317+
it 'deserializes correctly' do
318+
expected_value = {
319+
"git" => { "enabled" => 1, "base_url" => "https://git.example.com/public" },
320+
"subversion" => { "enabled" => 0 }
321+
}
322+
323+
expect(described_class.repository_checkout_data).to eq(expected_value)
324+
expect(described_class.find_by(name: 'repository_checkout_data').value).to eq(expected_value)
325+
end
326+
end
327+
306328
describe 'caching' do
307329
let(:cache_key) { described_class.send :cache_key }
308330

0 commit comments

Comments
 (0)