From 598c0b8e6869d7fc1f1830cb52e46d1d851d410c 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 Content-Type: text/plain; charset=utf-8 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 --- C4/Serials.pm | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index f56309e98c..c8a1bd38a6 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1118,19 +1118,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); @@ -1173,6 +1170,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.11.0