From d2d418e0471294fb64dbcafe677e9c39daad69fa Mon Sep 17 00:00:00 2001 From: Kirill Lyubaev Date: Wed, 27 Sep 2017 16:56:56 +0300 Subject: [PATCH 1/5] Added checker for _convertPath if the path is file --- lib/Raven/Client.php | 4 ++-- test/Raven/Tests/ClientTest.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Raven/Client.php b/lib/Raven/Client.php index 5b37844d9..5bcb3355d 100644 --- a/lib/Raven/Client.php +++ b/lib/Raven/Client.php @@ -285,8 +285,8 @@ private static function _convertPath($value) // we need app_path to have a trailing slash otherwise // base path detection becomes complex if the same // prefix is matched - if (substr($path, 0, 1) === DIRECTORY_SEPARATOR && substr($path, -1) !== DIRECTORY_SEPARATOR) { - $path = $path.DIRECTORY_SEPARATOR; + if ($path{0} === DIRECTORY_SEPARATOR && substr($path, -1) !== DIRECTORY_SEPARATOR && !is_file($path)) { + $path .= DIRECTORY_SEPARATOR; } return $path; } diff --git a/test/Raven/Tests/ClientTest.php b/test/Raven/Tests/ClientTest.php index 5bea1321e..943348fa6 100644 --- a/test/Raven/Tests/ClientTest.php +++ b/test/Raven/Tests/ClientTest.php @@ -1561,6 +1561,9 @@ public function test_convertPath() $this->assertEquals('foo/bar/', $property->invoke(null, 'foo/bar/')); $this->assertEquals(dirname(__DIR__).'/', $property->invoke(null, __DIR__.'/../')); $this->assertEquals(dirname(dirname(__DIR__)).'/', $property->invoke(null, __DIR__.'/../../')); + + $path = stream_get_meta_data($_ = tmpfile())['uri']; + $this->assertEquals($path, $property->invoke(null, $path)); } /** From aa85a8d236e135ee5131a811483d6e1fd38c73f2 Mon Sep 17 00:00:00 2001 From: Kirill Lyubaev Date: Mon, 9 Oct 2017 10:40:57 +0300 Subject: [PATCH 2/5] Added checker for _convertPath if the path is file --- lib/Raven/Client.php | 2 +- test/Raven/Tests/ClientTest.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/Raven/Client.php b/lib/Raven/Client.php index 5bcb3355d..7569969a9 100644 --- a/lib/Raven/Client.php +++ b/lib/Raven/Client.php @@ -285,7 +285,7 @@ private static function _convertPath($value) // we need app_path to have a trailing slash otherwise // base path detection becomes complex if the same // prefix is matched - if ($path{0} === DIRECTORY_SEPARATOR && substr($path, -1) !== DIRECTORY_SEPARATOR && !is_file($path)) { + if ($path{0} === DIRECTORY_SEPARATOR && substr($path, -1) !== DIRECTORY_SEPARATOR && substr($path, -4) !== '.php') { $path .= DIRECTORY_SEPARATOR; } return $path; diff --git a/test/Raven/Tests/ClientTest.php b/test/Raven/Tests/ClientTest.php index 943348fa6..3fa5c327c 100644 --- a/test/Raven/Tests/ClientTest.php +++ b/test/Raven/Tests/ClientTest.php @@ -1561,9 +1561,7 @@ public function test_convertPath() $this->assertEquals('foo/bar/', $property->invoke(null, 'foo/bar/')); $this->assertEquals(dirname(__DIR__).'/', $property->invoke(null, __DIR__.'/../')); $this->assertEquals(dirname(dirname(__DIR__)).'/', $property->invoke(null, __DIR__.'/../../')); - - $path = stream_get_meta_data($_ = tmpfile())['uri']; - $this->assertEquals($path, $property->invoke(null, $path)); + $this->assertEquals('src/App.php', $property->invoke(null, 'src/App.php')); } /** From 5d7ab5a5d470d1df5ab213737e8b0b47a508e8cd Mon Sep 17 00:00:00 2001 From: Kirill Lyubaev Date: Mon, 16 Oct 2017 10:32:12 +0300 Subject: [PATCH 3/5] Added checker for _convertPath if the path is file --- lib/Raven/Client.php | 16 ++++++++++++++-- test/Raven/Tests/ClientTest.php | 1 - 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Raven/Client.php b/lib/Raven/Client.php index 7569969a9..ea579147c 100644 --- a/lib/Raven/Client.php +++ b/lib/Raven/Client.php @@ -285,7 +285,7 @@ private static function _convertPath($value) // we need app_path to have a trailing slash otherwise // base path detection becomes complex if the same // prefix is matched - if ($path{0} === DIRECTORY_SEPARATOR && substr($path, -1) !== DIRECTORY_SEPARATOR && substr($path, -4) !== '.php') { + if ($path{0} === DIRECTORY_SEPARATOR && substr($path, -1) !== DIRECTORY_SEPARATOR) { $path .= DIRECTORY_SEPARATOR; } return $path; @@ -313,7 +313,19 @@ public function getExcludedAppPaths() public function setExcludedAppPaths($value) { - $this->excluded_app_paths = $value ? array_map(array($this, '_convertPath'), $value) : null; + if ($value) { + $excluded_app_paths = array(); + + // We should be able to exclude a php files + foreach ((array) $value as $path) { + $excluded_app_paths[] = substr($path, -4) !== '.php' ? self::_convertPath($path) : $path; + } + } else { + $excluded_app_paths = null; + } + + $this->excluded_app_paths = $excluded_app_paths; + return $this; } diff --git a/test/Raven/Tests/ClientTest.php b/test/Raven/Tests/ClientTest.php index 3fa5c327c..5bea1321e 100644 --- a/test/Raven/Tests/ClientTest.php +++ b/test/Raven/Tests/ClientTest.php @@ -1561,7 +1561,6 @@ public function test_convertPath() $this->assertEquals('foo/bar/', $property->invoke(null, 'foo/bar/')); $this->assertEquals(dirname(__DIR__).'/', $property->invoke(null, __DIR__.'/../')); $this->assertEquals(dirname(dirname(__DIR__)).'/', $property->invoke(null, __DIR__.'/../../')); - $this->assertEquals('src/App.php', $property->invoke(null, 'src/App.php')); } /** From c9c04d989bcc8c73f5bfb625c6a77435dca96dcc Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Sat, 21 Oct 2017 16:27:36 +0200 Subject: [PATCH 4/5] Test excluded paths setter with .php file --- test/Raven/Tests/ClientTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Raven/Tests/ClientTest.php b/test/Raven/Tests/ClientTest.php index 5bea1321e..efdeddf26 100644 --- a/test/Raven/Tests/ClientTest.php +++ b/test/Raven/Tests/ClientTest.php @@ -1455,10 +1455,10 @@ public function testGettersAndSetters() array('app_path', null, 'value', $property_method__convert_path->invoke($client, 'value')), array('app_path', null, null, ), array('app_path', null, false, null, ), - array('excluded_app_paths', null, array('value'), - array($property_method__convert_path->invoke($client, 'value'))), - array('excluded_app_paths', null, array(), null), array('excluded_app_paths', null, null), + array('excluded_app_paths', null, array(), null), + array('excluded_app_paths', null, array(__FILE__), array(__FILE__)), + array('excluded_app_paths', null, array(__DIR__), array(__DIR__ . DIRECTORY_SEPARATOR)), array('prefixes', null, array('value'), array($property_method__convert_path->invoke($client, 'value'))), array('prefixes', null, array()), array('send_callback', null, $callable), From 0167b64836b4576faac2cdb650f517648d35b9b4 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Sat, 21 Oct 2017 16:50:20 +0200 Subject: [PATCH 5/5] Add test to prove php files are excluded correctly --- test/Raven/Tests/StacktraceTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/Raven/Tests/StacktraceTest.php b/test/Raven/Tests/StacktraceTest.php index ed7b9f793..63b593e7b 100644 --- a/test/Raven/Tests/StacktraceTest.php +++ b/test/Raven/Tests/StacktraceTest.php @@ -205,15 +205,21 @@ public function testInAppWithExclusion() "line" => 3, "function" => "include_once", ), + array( + "file" => dirname(__FILE__) . '/resources/foo/c.php', + "line" => 3, + "function" => "include_once", + ) ); $frames = Raven_Stacktrace::get_stack_info( $stack, true, null, 0, null, dirname(__FILE__) . '/', - array(dirname(__FILE__) . '/resources/bar/')); + array(dirname(__FILE__) . '/resources/bar/', dirname(__FILE__) . '/resources/foo/c.php')); // stack gets reversed $this->assertEquals($frames[0]['in_app'], false); - $this->assertEquals($frames[1]['in_app'], true); + $this->assertEquals($frames[1]['in_app'], false); + $this->assertEquals($frames[2]['in_app'], true); } public function testBasePath()