feat: add player name redaction pass
Adds three lexical-context regexes (after-SteamID, ChatMessage author, Combat/Safety pvp subsystem) and wires the player-name branch in redact(). Includes six PHPUnit tests covering all three contexts plus the toggle-off and no-anchor-no-touch cases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,18 @@ class ProjectZomboidRedactor implements RedactorInterface
|
||||
/** Zeroed-out SteamID64 placeholder; syntactically valid but refers to no real account. */
|
||||
public const string STEAM_ID_REPLACEMENT = '76561198000000000';
|
||||
|
||||
/** Generic placeholder substituted for every matched player display name. */
|
||||
public const string PLAYER_NAME_REPLACEMENT = '<player>';
|
||||
|
||||
/** Matches a double-quoted player name that immediately follows the redacted Steam ID placeholder (cmd.txt / admin.txt shape); relies on the Steam ID pass having run first. */
|
||||
public const string PLAYER_AFTER_STEAMID_REGEX = '/(?<=76561198000000000) "(?<name>[^"]+)"/u';
|
||||
|
||||
/** Matches the author value inside a ChatMessage{...} envelope, using a fixed-length lookbehind on ", author='" and a lookahead on the closing "'" so only the bare name is replaced. */
|
||||
public const string PLAYER_IN_CHATMESSAGE_REGEX = '/(?<=, author=\')(?<name>[^\']+)(?=\')/u';
|
||||
|
||||
/** Matches the first double-quoted player name following a Combat: or Safety: subsystem token (pvp.txt shape); does NOT redact the second name after "hit" — deferred to v2. */
|
||||
public const string PLAYER_IN_PVP_SUBSYSTEM_REGEX = '/(?<=(?:Combat|Safety): )"(?<name>[^"]+)"/u';
|
||||
|
||||
private bool $redactSteamIds = true;
|
||||
private bool $redactPlayerNames = true;
|
||||
private bool $redactCoordinates = true;
|
||||
@@ -85,7 +97,9 @@ class ProjectZomboidRedactor implements RedactorInterface
|
||||
$content = preg_replace(self::STEAM_ID_REGEX, self::STEAM_ID_REPLACEMENT, $content);
|
||||
}
|
||||
if ($this->redactPlayerNames) {
|
||||
// Player name pass added in Task 3
|
||||
$content = preg_replace(self::PLAYER_AFTER_STEAMID_REGEX, ' "' . self::PLAYER_NAME_REPLACEMENT . '"', $content);
|
||||
$content = preg_replace(self::PLAYER_IN_CHATMESSAGE_REGEX, self::PLAYER_NAME_REPLACEMENT, $content);
|
||||
$content = preg_replace(self::PLAYER_IN_PVP_SUBSYSTEM_REGEX, '"' . self::PLAYER_NAME_REPLACEMENT . '"', $content);
|
||||
}
|
||||
if ($this->redactCoordinates) {
|
||||
// Coordinates pass added in Task 4
|
||||
|
||||
Reference in New Issue
Block a user