From 8548a24c54188a5220a5ff8efff5a0cff0d06acd Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Thu, 17 Mar 2022 16:19:16 +0100
Subject: [PATCH] Bug 30008: (bug 29690 follow-up) Fix Invalid data, cannot
 decode metadata object

Test plan:
1 - Find a record in the staff catalog
2 - Edit the record
3 - In the 520 notes field, add an ASCII escape character (27 decimal, 1b hex)
    On ubuntu Ctrl+Shift+u, then 1b, enter
4 - Save the record
5 - Set syspref ShowComponentRecords to 'both...'
6 - On record details: New->New child record
7 - Save the record
8 - Attempt to view the parent record in the staff client and opac

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
---
 catalogue/detail.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/catalogue/detail.pl b/catalogue/detail.pl
index e11e8d1567..2a635e10ef 100755
--- a/catalogue/detail.pl
+++ b/catalogue/detail.pl
@@ -198,7 +198,7 @@ foreach my $subscription (@subscriptions) {
 my $showcomp = C4::Context->preference('ShowComponentRecords');
 my $show_analytics;
 if ( $showcomp eq 'both' || $showcomp eq 'staff' ) {
-    if ( my $components = $biblio->get_marc_components(C4::Context->preference('MaxComponentRecords')) ) {
+    if ( my $components = $marc_record ? $biblio->get_marc_components(C4::Context->preference('MaxComponentRecords')) : undef ) {
         $show_analytics = 1 if @{$components}; # just show link when having results
         $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->object_messages};
         my $parts;
-- 
2.35.1