From 4aabe3d55bcdfa2a30562e679961482624327b49 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Thu, 12 Jan 2023 17:44:01 +0100 Subject: [PATCH] Bug 32615: Don't crash on empty yaml sysprefs To test: 1) Apply patch 2) Verify tests in t/Context.t pass --- C4/Context.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 1aec1232f3..77e38db581 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -341,14 +341,16 @@ the value cannot be properly decoded as YAML. sub yaml_preference { my ( $self, $preference ) = @_; + my $value = $self->preference( $preference ); + if ($value) { + my $yaml = eval { YAML::XS::Load( Encode::encode_utf8( $self->preference( $preference ) ) ); }; + if ($@) { + warn "Unable to parse $preference syspref : $@"; + return; + } - my $yaml = eval { YAML::XS::Load( Encode::encode_utf8( $self->preference( $preference ) ) ); }; - if ($@) { - warn "Unable to parse $preference syspref : $@"; - return; + return $yaml; } - - return $yaml; } =head2 enable_syspref_cache -- 2.35.1