From d54376a52374a2b83eadd40dd35d8bbfcba2de63 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 19 Mar 2020 14:20:38 +0100 Subject: [PATCH] Bug 24903: Special characters like parentheses in numbering pattern cause duplication in recievedlist Test plan: Use serial with a numbering pattern with parentheses like "2018 (No. 1)". Mark serial issue as arrived, check receivedlist on summary. Edit issue again, check if not duplicated on receivedlist. Mark issue as missing or not available, check missinglist. Mark missing issue as not missing, check list again. Signed-off-by: Marcel de Rooy Signed-off-by: Laurence Rault Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- C4/Serials.pm | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 3315959320..1c2840e3a2 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1119,19 +1119,16 @@ sub ModSerialStatus { my ( $missinglist, $recievedlist ) = $sth->fetchrow; if ( $status == ARRIVED || ($oldstatus == ARRIVED && $status != ARRIVED) ) { - $recievedlist .= "; $serialseq" - if ($recievedlist !~ /(^|;)\s*$serialseq(?=;|$)/); + $recievedlist = _handle_seqno($serialseq, $recievedlist); } # in case serial has been previously marked as missing if (grep /$status/, (EXPECTED, ARRIVED, LATE, CLAIMED)) { - $missinglist=~ s/(^|;)\s*$serialseq(?=;|$)//g; + $missinglist = _handle_seqno($serialseq, $missinglist, 'REMOVE'); } - $missinglist .= "; $serialseq" - if ( ( grep { $_ == $status } ( MISSING_STATUSES ) ) && ( $missinglist !~/(^|;)\s*$serialseq(?=;|$)/ ) ); - $missinglist .= "; not issued $serialseq" - if ( $status == NOT_ISSUED && $missinglist !~ /(^|;)\s*$serialseq(?=;|$)/ ); + $missinglist = _handle_seqno($serialseq, $missinglist) if grep { $_ == $status } MISSING_STATUSES; + $missinglist .= "; not issued $serialseq" if $status == NOT_ISSUED and not _handle_seqno($serialseq, $missinglist, 'CHECK'); $query = "UPDATE subscriptionhistory SET recievedlist=?, missinglist=? WHERE subscriptionid=?"; $sth = $dbh->prepare($query); @@ -1174,6 +1171,24 @@ sub ModSerialStatus { return; } +sub _handle_seqno { +# Adds or removes seqno from list when needed; returns list +# Or checks and returns true when present + + my ( $seq, $list, $op ) = @_; # op = ADD | REMOVE | CHECK (default: ADD) + my $seq_r = $seq; + $seq_r =~ s/([()])/\\$1/g; # Adjust disturbing parentheses for regex, maybe extend in future + + if( !$op or $op eq 'ADD' ) { + $list .= "; $seq" if $list !~ /(^|;)\s*$seq_r(?=;|$)/; + } elsif( $op eq 'REMOVE' ) { + $list=~ s/(^|;)\s*(not issued )?$seq_r(?=;|$)//g; + } else { # CHECK + return $list =~ /(^|;)\s*$seq_r(?=;|$)/ ? 1 : q{}; + } + return $list; +} + =head2 GetNextExpected $nextexpected = GetNextExpected($subscriptionid) -- 2.39.5