Skip to content

Commit

Permalink
Merge pull request #599 from SilverFire/fix/frame-unknown-file
Browse files Browse the repository at this point in the history
Prevent exception from Whoops when caught exception frame is not related to real file
  • Loading branch information
denis-sokolov authored Oct 23, 2018
2 parents a9f129b + 06e7f16 commit 8eb6d53
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Prevent exception in Whoops when caught exception frame is not related to real file

# 2.3.0

* Show previous exception messages.
Expand Down
4 changes: 2 additions & 2 deletions src/Whoops/Exception/Frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public function getArgs()
public function getFileContents()
{
if ($this->fileContentsCache === null && $filePath = $this->getFile()) {
// Leave the stage early when 'Unknown' is passed
// Leave the stage early when 'Unknown' or '[internal]' is passed
// this would otherwise raise an exception when
// open_basedir is enabled.
if ($filePath === "Unknown") {
if ($filePath === "Unknown" || $filePath === '[internal]') {
return null;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Whoops/Exception/FrameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ public function testGetFileContents()
$this->assertStringEqualsFile($data['file'], $frame->getFileContents());
}

/**
* @covers Whoops\Exception\Frame::getFileContents
* @testWith ["[internal]"]
* ["Unknown"]
* @see https://github.com/filp/whoops/pull/599
*/
public function testGetFileContentsWhenFrameIsNotRelatedToSpecificFile($fakeFilename)
{
$data = array_merge($this->getFrameData(), ['file' => $fakeFilename]);
$frame = $this->getFrameInstance($data);

$this->assertNull($frame->getFileContents());
}

/**
* @covers Whoops\Exception\Frame::getFileLines
*/
Expand Down

0 comments on commit 8eb6d53

Please sign in to comment.