2
0
forked from Wavyzz/dolibarr

UIUX: Interpret first token as thousands separator 21.500,00 (when French, ...). (#33832)

* Qual: Add testcase for price2num to convert '21.500,00' in FR

* NEW: Accept numbers like 1.213,00 in locales with whitespace/empty thousands separator

# NEW: Accept numbers like 1.213,00 in locales with whitespace/empty thousands separator

- Graceful handling of comma and dot as decimal points and thousands separators in the `price2num` function.
- Improved the `getNonEmptyString` function to include proper indentation and spacing (automatic).

* Add testcases for price2num

* en_US tests for invalid prices, add doc for price2num regex

* Restore lost test to validate compatibility

* Update FunctionsLibTest.php

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
MDW
2025-04-21 11:57:13 +02:00
committed by GitHub
parent e013e1c1b4
commit 69e3d4b5df
2 changed files with 71 additions and 39 deletions

View File

@@ -2,6 +2,7 @@
/* Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
* Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -482,10 +483,10 @@ class FunctionsLibTest extends CommonClassTest
/**
* testGetBrowserInfo
*
* @return void
*/
* testGetBrowserInfo
*
* @return void
*/
public function testGetBrowserInfo()
{
// MSIE 5.0
@@ -1618,6 +1619,9 @@ class FunctionsLibTest extends CommonClassTest
$this->assertEquals('12.4', price2num('12.4$'));
$this->assertEquals('12.4', price2num('12r.4$'));
$this->assertEquals('1.023210.00', price2num('1.023,210.00'), 'Test invalid 1.023,210.00 with en_US');
$this->assertEquals('1023.21000', price2num('1,023.210,00'), 'Test invalid 1,023.210,00 with en_US');
// For spanish language SeparatorThousand=. and SeparatorDecimal=,
$newlangs2 = new Translate('', $conf);
$newlangs2->setDefaultLang('es_ES');
@@ -1667,11 +1671,10 @@ class FunctionsLibTest extends CommonClassTest
$this->assertEquals(21500000, price2num('21 500 000'), 'Test 21 500 000 give 21500000 with french language');
$this->assertEquals(21500, price2num('21500.00'), 'Test 21500.00 give 21500 with french language');
$this->assertEquals(21500, price2num('21500,00'), 'Test 21500,00 give 21500 with french language');
/*
$this->assertEquals(21500, price2num('21.500,00'), 'Test 21.500,00 give 21500 with french language');
$this->assertEquals('1.023.210.00', price2num('1.023,210.00'), 'Test invalid 1.023,210.00 with french language');
$this->assertEquals('1.023.210.00', price2num('1,023.210,00'), 'Test invalid 1,023.210,00 with french language');
*/
$langs = $oldlangs;