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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Laurence Rault <laurence.rault@biblibre.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Marcel de Rooy 2020-03-19 14:20:38 +01:00 committed by Martin Renvoize
parent 0e2119570d
commit d54376a523
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 22 additions and 7 deletions

View File

@ -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)