use 5.010; use warnings; use strict; use Test::More 'no_plan'; use Test::NoWarnings; use constant SENSITIVE => qr{ password | user }xms;; VECTOR: for my $ar_vector ( [ q/{'password' => 'secret'}/, q/{'password' => '***'}/, ], [ q/{'password' => 'sec\'ret'}/, q/{'password' => '***'}/, ], [ q/{"password" => "secret"}/, q/{"password" => "***"}/, ], [ q/{"password" => "sec\"ret"}/, q/{"password" => "***"}/, ], [ q/{'password' : 'secret'}/, q/{'password' : '***'}/, ], [ q/{'password' : 'sec\'ret'}/, q/{'password' : '***'}/, ], [ q/{"password" : "secret"}/, q/{"password" : "***"}/, ], [ q/{"password" : "sec\"ret"}/, q/{"password" : "***"}/, ], [ q/{'user' => 'secret'}/, q/{'user' => '***'}/, ], [ q/{'user' => 'sec\'ret'}/, q/{'user' => '***'}/, ], [ q/{"user" => "secret"}/, q/{"user" => "***"}/, ], [ q/{"user" => "sec\"ret"}/, q/{"user" => "***"}/, ], [ q/{'user' : 'secret'}/, q/{'user' : '***'}/, ], [ q/{'user' : 'sec\'ret'}/, q/{'user' : '***'}/, ], [ q/{"user" : "secret"}/, q/{"user" : "***"}/, ], [ q/{"user" : "sec\"ret"}/, q/{"user" : "***"}/, ], ) { my ($string, $expected) = @$ar_vector; is elide(SENSITIVE, $string), $expected, "'$string' -> '$expected'"; } # end for VECTOR done_testing; # subroutines ###################################################### use constant { DQ => qr{ " [^\\"]* (?: \\. [^\\"]*)* " }xms, DQ_MASK => q{"***"}, SQ => qr{ ' [^\\']* (?: \\. [^\\']*)* ' }xms, SQ_MASK => q{'***'}, CONNECTOR => qr{ => | : }xms, }; sub elide { my ($key, $string, ) = @_; $string =~ s{ " $key " \s* ${ \CONNECTOR } \s* \K ${ \DQ } } {${ \DQ_MASK }}xmsg; $string =~ s{ ' $key ' \s* ${ \CONNECTOR } \s* \K ${ \SQ } } {${ \SQ_MASK }}xmsg; return $string; }