Skip to content

Commit

Permalink
Fix decode octal regex (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdiasb12 authored May 20, 2021
1 parent e7e4503 commit 0aa0180
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Smalot/PdfParser/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ public static function decodeHexadecimal($hexa, $add_braces = false)
*/
public static function decodeOctal($text)
{
$parts = preg_split('/(\\\\\d{3})/s', $text, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE);
$parts = preg_split('/(\\\\[0-7]{3})/s', $text, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE);
$text = '';

foreach ($parts as $part) {
if (preg_match('/^\\\\\d{3}$/', $part)) {
if (preg_match('/^\\\\[0-7]{3}$/', $part)) {
$text .= \chr(octdec(trim($part, '\\')));
} else {
$text .= $part;
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/FontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ public function testDecodeOctal()
{
$this->assertEquals('AB C', Font::decodeOctal('\\101\\102\\040\\103'));
$this->assertEquals('AB CD', Font::decodeOctal('\\101\\102\\040\\103D'));
$this->assertEquals('AB \199', Font::decodeOctal('\\101\\102\\040\\199'));
}

public function testDecodeEntities()
Expand Down

0 comments on commit 0aa0180

Please sign in to comment.