Shuffle/app/lib/features/auth/domain/validation/display_name_rule.dart
cschlaefke 54337ffc59 feat(auth): add auth domain, repository, validators and router redirects
Refs #1

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 00:09:47 +01:00

42 lines
1.4 KiB
Dart
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/// Fehler des Anzeigenamens.
enum DisplayNameError {
empty,
tooLong,
/// Enthält U+200B (Zero Width Space). Die UI zeigt dieselbe Meldung wie für
/// einen ungültigen Namen (Spec #1 § 5.4), kein eigener Text.
invalidCharacter,
}
/// Regel für Anzeigenamen (KTO-01 Kriterium 10, KTO-02 Kriterium 1).
///
/// Identisch zum Server (`public.trim_ws` + `char_length`): Leerraum am Rand
/// wird entfernt (Dart `trim()` und `trim_ws` entfernen dieselben Zeichen,
/// auch NBSP und Tab). Danach 1 bis 30 Unicode-Codepoints, gezählt über
/// `runes`, nicht über `String.length` (UTF-16). U+200B wird nicht getrimmt,
/// sondern überall abgelehnt.
abstract final class DisplayNameRule {
static const maxLength = 30;
static const zeroWidthSpace = '​';
/// Der Wert, der gespeichert und gesendet wird.
static String normalize(String value) => value.trim();
/// Länge in Codepoints nach dem Trim (für den Zähler `n/30`).
static int length(String value) => normalize(value).runes.length;
static DisplayNameError? validate(String value) {
final name = normalize(value);
if (name.contains(zeroWidthSpace)) {
return DisplayNameError.invalidCharacter;
}
final count = name.runes.length;
if (count == 0) {
return DisplayNameError.empty;
}
if (count > maxLength) {
return DisplayNameError.tooLong;
}
return null;
}
}