From ed5f3898fc3b488334f106068cfa2e8af88a57bb Mon Sep 17 00:00:00 2001 From: Jan Orel Date: Mon, 10 Jun 2024 13:44:50 +0200 Subject: [PATCH] B #-: Parse yaml with aliases in ruby 3.1 (#2984) (#3097) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tino Vázquez --- src/sunstone/models/SunstoneViews.rb | 12 ++++++++++-- src/sunstone/sunstone-server.rb | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/sunstone/models/SunstoneViews.rb b/src/sunstone/models/SunstoneViews.rb index e8c7ef2ea0..1ed7fd7611 100644 --- a/src/sunstone/models/SunstoneViews.rb +++ b/src/sunstone/models/SunstoneViews.rb @@ -35,7 +35,11 @@ class SunstoneViews raise "Sunstone configuration file does not contain default view mode, aborting" if mode.nil? - @views_config = YAML.load_file(VIEWS_CONFIGURATION_FILE) + if Psych::VERSION > '4.0' + @views_config = YAML.load_file(VIEWS_CONFIGURATION_FILE, aliases: true) + else + @views_config = YAML.load_file(VIEWS_CONFIGURATION_FILE) + end base_path = SUNSTONE_ROOT_DIR+'/public/js/' @@ -49,7 +53,11 @@ class SunstoneViews reg = VIEWS_CONFIGURATION_DIR + mode + '/' m = p_path.match(/^#{reg}(.*).yaml$/) if m && m[1] - @views[m[1]] = YAML.load_file(p_path) + if Psych::VERSION > '4.0' + @views[m[1]] = YAML.load_file(p_path, aliases: true) + else + @views[m[1]] = YAML.load_file(p_path) + end end end end diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index a2d85e41d1..8464d2a398 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -158,7 +158,11 @@ end ############################################################################## begin - $conf = YAML.load_file(CONFIGURATION_FILE) + if Psych::VERSION > '4.0' + $conf = YAML.load_file(CONFIGURATION_FILE, aliases: true) + else + $conf = YAML.load_file(CONFIGURATION_FILE) + end rescue Exception => e STDERR.puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}" exit 1 @@ -359,7 +363,11 @@ helpers do def build_conf_locals logos_conf = nil begin - logos_conf = YAML.load_file(LOGOS_CONFIGURATION_FILE) + if Psych::VERSION > '4.0' + logos_conf = YAML.load_file(LOGOS_CONFIGURATION_FILE, aliases: true) + else + logos_conf = YAML.load_file(LOGOS_CONFIGURATION_FILE) + end rescue Exception => e logger.error { "Error parsing config file #{LOGOS_CONFIGURATION_FILE}: #{e.message}" } error 500, ""