Skip to content

Commit

Permalink
terminology: blacklist -> filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mindplay-dk committed Mar 6, 2019
1 parent 3562ece commit eccfcfa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ The constructor accepts two optional argument:

* `$root_path` - if specified, the project root-path will be removed from visible filenames in stack-traces.
* `$max_string_length` - specifies the maximum length at which reported PHP values will be truncated.
* `$blacklist` - specifies one or more filename patterns to blacklist from stack-traces.
* `$filters` - specifies one or more filename patterns to be filtered from stack-traces.

In addition, the public `$error_levels` property lets you customize how PHP error-levels map to
Sentry severity-levels. The default configuration matches that of the official 2.0 client.
Expand Down
24 changes: 12 additions & 12 deletions src/Extensions/ExceptionReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class ExceptionReporter implements SentryClientExtension
protected $max_string_length;

/**
* @var string[] file-name patterns to blacklist from stack-traces
* @var string[] file-name patterns to filter from stack-traces
*/
protected $blacklist;
protected $filters;

/**
* Severity of `ErrorException` mappings are identical to the official (2.0) client
Expand Down Expand Up @@ -76,24 +76,24 @@ class ExceptionReporter implements SentryClientExtension
/**
* The optional `$root_path`, if given, will be stripped from filenames.
*
* The optional `$blacklist` is an array of {@see \fnmatch()} patterns, which will be applied
* The optional `$filters` is an array of {@see \fnmatch()} patterns, which will be applied
* to relative paths of source-file references in stack-traces. You can use this to filter
* scripts that define/bootstrap sensitive values like passwords and hostnames, so that
* these lines will never show up in a stack-trace.
*
* @param string|null $root_path absolute project root-path (e.g. Composer root path; optional)
* @param int $max_string_length PHP values longer than this will be truncated
* @param string[] $blacklist Optional file-name patterns to blacklist from stack-traces
* @param string[] $filters Optional file-name patterns to filter from stack-traces
*/
public function __construct(?string $root_path = null, $max_string_length = 200, array $blacklist = [])
public function __construct(?string $root_path = null, $max_string_length = 200, array $filters = [])
{
$this->root_path = $root_path
? rtrim($root_path, "/\\") . "/"
: null;

$this->max_string_length = $max_string_length;

$this->blacklist = $blacklist;
$this->filters = $filters;
}

public function apply(Event $event, Throwable $exception, ?ServerRequestInterface $request): void
Expand Down Expand Up @@ -197,8 +197,8 @@ protected function createStackFrame(array $entry): StackFrame
$frame->filename = substr($filename, strlen($this->root_path));
}

if ($this->isBlacklisted($filename)) {
$frame->context_line = "### BLACKLISTED ###";
if ($this->isFiltered($filename)) {
$frame->context_line = "### FILTERED FILE ###";
} else {
if ($filename !== self::NO_FILE) {
$this->loadContext($frame, $filename, $lineno, 5);
Expand All @@ -215,13 +215,13 @@ protected function createStackFrame(array $entry): StackFrame
/**
* @param string $filename absolute path to source-file
*
* @return bool true, if the given file matches any defined blacklist pattern
* @return bool true, if the given file matches any defined filter pattern
*
* @see $blacklist
* @see $filters
*/
protected function isBlacklisted(string $filename): bool
protected function isFiltered(string $filename): bool
{
foreach ($this->blacklist as $pattern) {
foreach ($this->filters as $pattern) {
if (fnmatch($pattern, substr($filename, strlen($this->root_path)))) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions test/test.fixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class MockSentryClient extends SentryClient
*/
public $time = 1538738714;

public function __construct(EventCapture $capture, ?array $extensions = null, ?array $blacklist = [])
public function __construct(EventCapture $capture, ?array $extensions = null, ?array $filters = [])
{
$this->logger = new BreadcrumbLogger();

Expand All @@ -122,7 +122,7 @@ public function __construct(EventCapture $capture, ?array $extensions = null, ?a
$extensions ?: [
new EnvironmentReporter(),
new RequestReporter(),
new ExceptionReporter(__DIR__, 200, $blacklist),
new ExceptionReporter(__DIR__, 200, $filters),
new ClientSniffer(),
new ClientIPDetector(),
]
Expand Down
20 changes: 10 additions & 10 deletions test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ function () {
}
);

function test_exception_capture($use_blacklist = false) {
return function () use ($use_blacklist) {
function test_exception_capture($use_filter = false) {
return function () use ($use_filter) {
$dsn = new MockDSN();

$capture = new MockDirectEventCapture($dsn);

$client = new MockSentryClient(
$capture,
null,
$use_blacklist
$use_filter
? ["*.fixtures.php"]
: []
);
Expand Down Expand Up @@ -181,16 +181,16 @@ function test_exception_capture($use_blacklist = false) {
eq($inner_frames[2]["lineno"], 34);
eq($inner_frames[3]["lineno"], 31, "can capture line-number of failed call-site");

$BLACKLISTED = "### BLACKLISTED ###";
$FILTERED = "### FILTERED FILE ###";

if ($use_blacklist) {
ok(! isset($inner_frames[0]["pre_context"]), "can blacklist pre_context");
if ($use_filter) {
ok(! isset($inner_frames[0]["pre_context"]), "filtering removes pre_context");

eq($inner_frames[0]["context_line"], $BLACKLISTED, "can blacklist context_line");
eq($inner_frames[0]["context_line"], $FILTERED, "filtering removes context_line");

ok(! isset($inner_frames[0]["post_context"]), "can blacklist post_context");
ok(! isset($inner_frames[0]["post_context"]), "filtering removes post_context");

ok(! isset($inner_frames[0]["vars"]), "can blacklist arguments");
ok(! isset($inner_frames[0]["vars"]), "filtering omits arguments");
} else {
eq(
$inner_frames[0]["pre_context"],
Expand Down Expand Up @@ -242,7 +242,7 @@ function test_exception_capture($use_blacklist = false) {
);

test(
"can capture Exception without vars and stack-traces from files matching a blacklist pattern",
"can capture Exception without vars and stack-traces from files matching a filter pattern",
test_exception_capture(true)
);

Expand Down

0 comments on commit eccfcfa

Please sign in to comment.