Skip to content

Commit

Permalink
Guard against possible mixed types
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Oct 7, 2022
1 parent 279dd98 commit a4b127f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

## [Unreleased][unreleased]

### Fixed

- Fixed missing type checks and coercions

## [5.1.0] - 2022-03-02

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/Converter/LinkConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ private function isValidEmail(string $email): bool

private function shouldStrip(): bool
{
return $this->config->getOption('strip_placeholder_links') ?? false;
return \boolval($this->config->getOption('strip_placeholder_links') ?? false);
}
}
4 changes: 2 additions & 2 deletions src/Converter/ListItemConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function convert(ElementInterface $element): string
}

if ($listType === 'ul') {
$listItemStyle = $this->config->getOption('list_item_style', '-');
$listItemStyleAlternate = $this->config->getOption('list_item_style_alternate');
$listItemStyle = \strval($this->config->getOption('list_item_style', '-'));
$listItemStyleAlternate = \strval($this->config->getOption('list_item_style_alternate', ''));
if (! isset($this->listItemStyle)) {
$this->listItemStyle = $listItemStyleAlternate ?: $listItemStyle;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Converter/TableConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function convert(ElementInterface $element): string
}

$value = \str_replace("\n", ' ', $value);
$value = \str_replace('|', $this->config->getOption('table_pipe_escape') ?? '\|', $value);
$value = \str_replace('|', \strval($this->config->getOption('table_pipe_escape') ?? '\|'), $value);

return '| ' . \trim($value) . ' ';
case 'thead':
Expand Down
4 changes: 3 additions & 1 deletion src/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public function getChildren(): array
{
$ret = [];
foreach ($this->node->childNodes as $node) {
$ret[] = new self($node);
if ($node instanceof \DOMNode) {
$ret[] = new self($node);
}
}

return $ret;
Expand Down
2 changes: 1 addition & 1 deletion src/HtmlConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected function convertToMarkdown(ElementInterface $element): string
$tag = $element->getTagName();

// Strip nodes named in remove_nodes
$tagsToRemove = \explode(' ', $this->getConfig()->getOption('remove_nodes') ?? '');
$tagsToRemove = \explode(' ', \strval($this->getConfig()->getOption('remove_nodes') ?? ''));
if (\in_array($tag, $tagsToRemove, true)) {
return '';
}
Expand Down

0 comments on commit a4b127f

Please sign in to comment.