From c2658f88d5204940896d37acea9cfbcc2845fde6 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 24 Mar 2020 08:51:29 -0400 Subject: [PATCH] Bug 24966: Fix calls to maybe_add where method call does not return a value For reasons unknown to me, a call like: -- $resp .= maybe_add( FID_CALL_NUMBER, $item->call_number, $server ); -- will not work as expected if the item has no callnumber. One would expect the parameters to the subroutine to be: 'CY', under, and a SIPServer object. What is actually received is: 'CY', and a SIPServer object. We ingest the parameters like so: -- sub maybe_add { my ($fid, $value, $server) = @_; -- So, what happens is $value is populated with the server object! This can cause bad output like this: -- OUTPUT MSG: '101YNN20200324 063701AOBPL|AB32503201584185|AQBPL|AJCat /|CK001|CRn|CSJ 636.8 CLU|CYC4::SIP::SIPServer=HASH(0x1ea0e58)|DAC4::SIP::SIPServer=HASH(0x1ea0e58)|' -- Test Plan: 1) On master, perform a checkin of an item not on hold using the sip cli tester 2) Note some fields contain something like 'C4::SIP::SIPServer=HASH(0x1ea0e58)' 3) Apply this patch 4) Restart the SIP server 5) Perform the SIP checkin again 6) Those fields from step 2 should be gone! Signed-off-by: Kyle M Hall Signed-off-by: Barbara Johnson --- C4/SIP/Sip.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/C4/SIP/Sip.pm b/C4/SIP/Sip.pm index a708fa148a..4eb33638fd 100644 --- a/C4/SIP/Sip.pm +++ b/C4/SIP/Sip.pm @@ -60,6 +60,9 @@ sub timestamp { sub add_field { my ($field_id, $value, $server) = @_; + # $value may be populated with the $server object if the method call did not return anything + ( $value, $server ) = ( $server, $value ) if ref($value) eq 'C4::SIP::SIPServer'; + if ( my $hide_fields = $server->{account}->{hide_fields} ) { my @fields = split( ',', $hide_fields ); return q{} if first { $_ eq $field_id } @fields; @@ -94,6 +97,9 @@ sub add_field { sub maybe_add { my ($fid, $value, $server) = @_; + # $value may be populated with the $server object if the method call did not return anything + ( $value, $server ) = ( $server, $value ) if ref($value) eq 'C4::SIP::SIPServer'; + if ( my $hide_fields = $server->{account}->{hide_fields} ) { my @fields = split( ',', $hide_fields ); return q{} if first { $_ eq $fid } @fields; -- 2.21.1 (Apple Git-122.3)