Skip to content

Commit

Permalink
Replaces #403 (fix Call to a member function getFontSpaceLimit() on n…
Browse files Browse the repository at this point in the history
…ull) (#406)

* try to trigger error which is mentioned in #403
* allow CI to run on all push events
* reverted changes to provoke error message, error: Call to a member function getFontSpaceLimit() on null
* deployed fixes by @xfolder; added test case to reproduce error
* refined test function
* PHPUnit::expectNotToPerformAssertions not available when using PHP 5.6 and 7.0; Use doesNotPerformAssertions as PHP doc comment.

Co-authored-by: Mirko <[email protected]>
  • Loading branch information
k00ni and xfolder authored Apr 13, 2021
1 parent b8784eb commit 1895c17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Smalot/PdfParser/PDFObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private function getDefaultFont(Page $page = null)
return reset($fonts);
}

return new Font($this->document);
return new Font($this->document, null, null, $this->config);
}

/**
Expand Down Expand Up @@ -488,7 +488,7 @@ public function getTextArray(Page $page = null)
{
$text = [];
$sections = $this->getSectionsText($this->content);
$current_font = new Font($this->document);
$current_font = new Font($this->document, null, null, $this->config);

foreach ($sections as $section) {
$commands = $this->getCommandsText($section);
Expand Down
20 changes: 20 additions & 0 deletions tests/Integration/FontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

namespace Tests\Smalot\PdfParser\Integration;

use Smalot\PdfParser\Config;
use Smalot\PdfParser\Document;
use Smalot\PdfParser\Element;
use Smalot\PdfParser\Encoding;
Expand Down Expand Up @@ -348,6 +349,25 @@ public function testDecodeText()
$this->assertEquals('æöü', $font->decodeText($commands));
}

/**
* Tests buggy behavior which lead to:
*
* Call to a member function getFontSpaceLimit() on null
*
* @see https://github.com/smalot/pdfparser/pull/403
*
* @doesNotPerformAssertions
*/
public function testTriggerGetFontSpaceLimitOnNull()
{
// error is triggered, if we set the fourth parameter to null
$font = new Font(new Document(), null, null, new Config());

// both functions can trigger the error
$font->decodeText([]);
$font->getTextArray();
}

public function testXmlContent()
{
$filename = $this->rootDir.'/samples/bugs/Issue18.pdf';
Expand Down

0 comments on commit 1895c17

Please sign in to comment.