Skip to content

Commit 0c14eeb

Browse files
committed
fix: corrected wrong usage of allowedLinkHosts(), closes #3555
1 parent 3be23b5 commit 0c14eeb

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

phpmyfaq/src/phpMyFAQ/Helper/FaqHelper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ public function cleanUpContent(string $content): string
175175
->allowMediaSchemes(['https', 'http', 'mailto', 'data'])
176176
->allowMediaHosts($allowedHosts)
177177
->allowLinkSchemes(['https', 'http', 'mailto', 'data'])
178-
->allowLinkHosts($allowedHosts)
179178
);
180179

181180
$sanitizedContent = $htmlSanitizer->sanitize($content);

tests/phpMyFAQ/Helper/FaqHelperTest.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@
1010
use phpMyFAQ\System;
1111
use phpMyFAQ\Translation;
1212
use PHPUnit\Framework\TestCase;
13-
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
1413

1514
class FaqHelperTest extends TestCase
1615
{
17-
/** @var Configuration */
18-
private Configuration $configuration;
19-
2016
/** @var FaqHelper*/
2117
private FaqHelper $faqHelper;
2218

@@ -34,15 +30,15 @@ protected function setUp(): void
3430

3531
$dbHandle = new Sqlite3();
3632
$dbHandle->connect(PMF_TEST_DIR . '/test.db', '', '');
37-
$this->configuration = new Configuration($dbHandle);
38-
$this->configuration->set('main.currentVersion', System::getVersion());
39-
$this->configuration->set('main.referenceURL', 'https://localhost:443/');
40-
$this->configuration->set('records.allowedMediaHosts', 'www.youtube.com,example.com,phpmyfaq.de');
33+
$configuration = new Configuration($dbHandle);
34+
$configuration->set('main.currentVersion', System::getVersion());
35+
$configuration->set('main.referenceURL', 'https://localhost:443/');
36+
$configuration->set('records.allowedMediaHosts', 'www.youtube.com,example.com,phpmyfaq.de');
4137

42-
$language = new Language($this->configuration);
43-
$this->configuration->setLanguage($language);
38+
$language = new Language($configuration);
39+
$configuration->setLanguage($language);
4440

45-
$this->faqHelper = new FaqHelper($this->configuration);
41+
$this->faqHelper = new FaqHelper($configuration);
4642
}
4743

4844
public function testRewriteLanguageMarkupClass(): void
@@ -78,7 +74,8 @@ public function testCreateFaqUrl(): void
7874

7975
public function testCleanUpContent(): void
8076
{
81-
$content = '<p>Some text <script>alert("Hello, world!");</script><img src=foo onerror=alert(document.cookie)></p>';
77+
$content = '<p>Some text <script>alert("Hello, world!");' .
78+
'</script><img src=foo onerror=alert(document.cookie)></p>';
8279
$expectedOutput = '<p>Some text <img src="foo" /></p>';
8380

8481
$actualOutput = $this->faqHelper->cleanUpContent($content);
@@ -151,6 +148,16 @@ public function testCleanUpContentWithDifferentImageSource(): void
151148
$this->assertEquals($expectedOutput, $actualOutput);
152149
}
153150

151+
public function testExternalLinks(): void
152+
{
153+
$content = '<a rel="nofollow" target="_blank" href="https://www.phpmyfaq.de">phpMyFAQ</a>';
154+
$expectedOutput = '<a rel="nofollow" target="_blank" href="https://www.phpmyfaq.de">phpMyFAQ</a>';
155+
156+
$actualOutput = $this->faqHelper->cleanUpContent($content);
157+
158+
$this->assertEquals($expectedOutput, $actualOutput);
159+
}
160+
154161
public function testConvertOldInternalLinks(): void
155162
{
156163
// Test questions for slug generation

0 commit comments

Comments
 (0)