From 4f3062c4ecd43ea361b7c8033ce1220bb99233dd Mon Sep 17 00:00:00 2001 From: Baptiste Date: Thu, 31 Oct 2024 17:37:53 +0100 Subject: [PATCH] Bug 38360: Price extraction from MungeMarcPrice should be improved MungeMarcPrice's "rescue mode", tries and catch the whole possible number patterns in one regexp, which leads to very curious authorized values, and can leave some price unmatched for curious reasons. Unmatched price that should be: 49.3 ; 555,555.3 (only 1 digit after separator) 50 (no digit) Matched prices that should not: ,,,,,,,35 ; ,.,..,.45 ; 99,999.999,99 TEST PLAN (for UNIMARC): 1 - Apply first commit, run tests (prove t/db_dependent/MungeMarcPrice.t) -> they should fail 1 - Export a MARC NOTICE in marxml with a 010d filled with 49.3 2 - On acquisition, register a new vendor 3 - Add a Basket to this vendor 4 - Add an order -> from a file -> select the exported marc notice 5 - Check the checkbox associated with this item -> there is no price field filled 6 - APPLY PATCH 7 - Repeat 4 & 5 -> the price is now displayed 8 - Run tests -> all tests pass --- C4/Biblio.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 51b1e036789..682cd8963cc 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1325,7 +1325,11 @@ sub MungeMarcPrice { $price = $localprice; } else { ## Grab the first number in the string ( can use commas or periods for thousands separator and/or decimal separator ) - ( $price ) = $price =~ m/([\d\,\.]+[[\,\.]\d\d]?)/; + my $computed_price; + ($computed_price) = $price =~ m/(^\s*\d+(\.\d{3})+([\,]\d+)?)/g; + ($computed_price) = $price =~ m/(^\s*\d+(,\d{3})+([\.]\d+)?)/ unless $computed_price; + ($computed_price) = $price =~ m/(^\s*\d+([\.,]\d+)?)/ unless $computed_price; + $price = $computed_price ? $computed_price : ''; } # eliminate symbol/isocode, space and any final dot from the string $price =~ s/[\p{Sc}\p{L}\/ ]|\.$//g; -- 2.30.2