maskDsn function

String maskDsn(
  1. String dsn
)

dsn with its password-shaped parts replaced for display: the userinfo password of a URL (postgres://app:secret@…) and password=/pwd= key-value segments (ADO-style strings). Copy still copies the real value — this guards screenshots and screen shares, not the developer's own machine.

Implementation

String maskDsn(String dsn) => dsn
    .replaceFirstMapped(
      RegExp(r'://([^/@]*):([^/@]*)@'),
      (m) => '://${m[1]}:••••@',
    )
    .replaceAllMapped(
      RegExp(r'(password|pwd)(\s*=\s*)[^;]+', caseSensitive: false),
      (m) => '${m[1]}${m[2]}••••',
    );