mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-18 17:31:35 +00:00
Support comma as decimal separator in SI value parsing
Part names using European decimal notation (e.g. "4,7 kΩ", "2,2uF") were parsed incorrectly because the regex only recognized dots. Now commas are normalized to dots before parsing, matching the existing pattern used elsewhere in the codebase (PartNormalizer, price providers).
This commit is contained in:
parent
f75c5d7dd9
commit
93b9b29b3b
2 changed files with 18 additions and 4 deletions
|
|
@ -37,7 +37,7 @@ final class SiValueSortTest extends AbstractDoctrineFunctionTestCase
|
|||
$sql = $function->getSql($this->createSqlWalker(new PostgreSQLPlatform()));
|
||||
|
||||
$this->assertStringContainsString('CASE', $sql);
|
||||
$this->assertStringContainsString('substring(part_name', $sql);
|
||||
$this->assertStringContainsString("REPLACE(part_name, ',', '.')", $sql);
|
||||
$this->assertStringContainsString('1e-12', $sql);
|
||||
$this->assertStringContainsString('1e-9', $sql);
|
||||
$this->assertStringContainsString('1e-6', $sql);
|
||||
|
|
@ -56,7 +56,7 @@ final class SiValueSortTest extends AbstractDoctrineFunctionTestCase
|
|||
$sql = $function->getSql($this->createSqlWalker(new MySQLPlatform()));
|
||||
|
||||
$this->assertStringContainsString('CASE', $sql);
|
||||
$this->assertStringContainsString('REGEXP_SUBSTR(part_name', $sql);
|
||||
$this->assertStringContainsString("REPLACE(part_name, ',', '.')", $sql);
|
||||
$this->assertStringContainsString('1e-12', $sql);
|
||||
$this->assertStringContainsString('1e6', $sql);
|
||||
}
|
||||
|
|
@ -106,11 +106,16 @@ final class SiValueSortTest extends AbstractDoctrineFunctionTestCase
|
|||
yield 'plain_integer' => ['100', 100.0];
|
||||
yield 'plain_decimal' => ['4.7', 4.7];
|
||||
|
||||
// Decimal values with prefix
|
||||
// Decimal values with prefix (dot separator)
|
||||
yield 'decimal_nano' => ['4.7nF', 4.7e-9];
|
||||
yield 'decimal_micro' => ['0.1uF', 0.1e-6];
|
||||
yield 'decimal_kilo' => ['2.2k', 2.2e3];
|
||||
|
||||
// Comma decimal separator (European locale)
|
||||
yield 'comma_kilo' => ['4,7k', 4.7e3];
|
||||
yield 'comma_micro' => ['2,2uF', 2.2e-6];
|
||||
yield 'comma_kilo_space' => ['1,2 kΩ', 1.2e3];
|
||||
|
||||
// Number NOT at the start — should return NULL
|
||||
yield 'prefixed_name' => ['CAP-100nF', null];
|
||||
yield 'name_with_number' => ['R 4.7k 1%', null];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue