Fix Samsung density-code regex to honor fixed field width

The lazy quantifier {4,6}? never expanded beyond its minimum because
the trailing greedy [A-Z0-9]* always absorbed the rest up to the
hyphen, so a longer density code would silently be truncated to 5
chars and could match an unrelated table entry, producing wrong specs
instead of null. The density code is actually fixed-width (A + 4
chars); the revision after it is the variable part. Tighten the
pattern to {4}, rewrite the stale comment (which still claimed a fixed
3-char revision), and add a test that every Samsung density key is
exactly 5 characters so a future mismatched table entry can't silently
become unreachable.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
vchuser
2026-07-28 14:41:24 +02:00
co-authored by Claude Opus 5
parent e14d607761
commit 4201643fc5
2 changed files with 17 additions and 7 deletions
+8
View File
@@ -1,6 +1,7 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { decodePartNumber } from '../src/pn-decoder.js';
import { VENDOR_TABLES } from '../src/pn-tables.js';
test('dekodiert die Samsung-Teilenummer aus dem Referenzmodul', () => {
const spec = decodePartNumber('M386A8K40BM1-CRC4Y');
@@ -55,3 +56,10 @@ test('erkennt Bauform und Geschwindigkeit auch mit vierteiliger Revision', () =>
assert.equal(spec.capacityGb, null, 'unbekannter Dichte-Code laesst das Feld offen');
assert.equal(spec.partNumber, 'M393A2K43BBX1-CTD');
});
test('Samsung-Dichte-Codes sind exakt fuenf Zeichen lang (feste Feldbreite im Muster)', () => {
const samsung = VENDOR_TABLES.find((table) => table.vendor === 'Samsung');
for (const key of Object.keys(samsung.density)) {
assert.equal(key.length, 5, `Dichte-Code '${key}' hat nicht die geforderte Laenge 5 und waere im Muster wirkungslos`);
}
});