1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-02 22:57:26 +02:00

refactor: general code base refactor (#2950)

* refactor

* fix: bug in previous refactor

* chore: exclude phpcompat sniff due to bug in phpcompat

* fix: do not leak absolute paths

* refactor/fix: batch extensions checking, fix DOS issue
This commit is contained in:
Dag
2022-08-06 22:46:28 +02:00
committed by GitHub
parent b042412416
commit 2bbce8ebef
45 changed files with 679 additions and 827 deletions

View File

@@ -63,7 +63,10 @@ abstract class FormatAbstract implements FormatInterface
{
$charset = $this->charset;
return is_null($charset) ? static::DEFAULT_CHARSET : $charset;
if (is_null($charset)) {
return static::DEFAULT_CHARSET;
}
return $charset;
}
/**
@@ -93,7 +96,7 @@ abstract class FormatAbstract implements FormatInterface
public function getItems()
{
if (!is_array($this->items)) {
throw new \LogicException('Feed the ' . get_class($this) . ' with "setItems" method before !');
throw new \LogicException(sprintf('Feed the %s with "setItems" method before !', get_class($this)));
}
return $this->items;
@@ -126,26 +129,4 @@ abstract class FormatAbstract implements FormatInterface
return $this->extraInfos;
}
/**
* Sanitize HTML while leaving it functional.
*
* Keeps HTML as-is (with clickable hyperlinks) while reducing annoying and
* potentially dangerous things.
*
* @param string $html The HTML content
* @return string The sanitized HTML content
*
* @todo This belongs into `html.php`
* @todo Maybe switch to http://htmlpurifier.org/
* @todo Maybe switch to http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/index.php
*/
protected function sanitizeHtml(string $html): string
{
$html = str_replace('<script', '<&zwnj;script', $html); // Disable scripts, but leave them visible.
$html = str_replace('<iframe', '<&zwnj;iframe', $html);
$html = str_replace('<link', '<&zwnj;link', $html);
// We leave alone object and embed so that videos can play in RSS readers.
return $html;
}
}