From 36e6b8df11fd4635adb1df5245904a848ab22003 Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Mon, 29 Dec 2025 11:12:44 +0000 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 cdfde492d65..13f89cf3103 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1416,7 +1416,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 -- 2.43.0