Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…for target attribute

#5
  • Loading branch information
Gemorroj committed Jun 28, 2023
1 parent 93ac001 commit 42796b3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Tag/TagAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,6 @@ protected function isValidOlType(string $olType): bool

protected function isValidTarget(string $target): bool
{
return \in_array(\strtolower($target), ['_blank', '_self', '_parent', '_top'], true);
return \in_array(\strtolower($target), ['_blank', '_self', '_parent', '_top'], true) || \preg_match('/^[^\W_]\w+$/', $target);
}
}
26 changes: 26 additions & 0 deletions tests/Tag/TagAbstractTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Xbbcode\Tests\Tag;

use PHPUnit\Framework\TestCase;
use Xbbcode\Tag\TagAbstract;

class TagAbstractTest extends TestCase
{
public function testTarget(): void
{
$validTargets = ['_blank', '_self', '_parent', '_top', 'any_anchor', '123'];
$invalidTargets = ['_fake', '_123'];

$mock = $this->getMockForAbstractClass(TagAbstract::class);
$method = new \ReflectionMethod($mock, 'isValidTarget');
$method->setAccessible(true);

foreach ($validTargets as $target) {
self::assertTrue($method->invoke($mock, $target));
}
foreach ($invalidTargets as $target) {
self::assertFalse($method->invoke($mock, $target));
}
}
}
2 changes: 1 addition & 1 deletion tests/XbbcodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class XbbcodeTest extends TestCase
{
public function testBase()
public function testBase(): void
{
$text = '
Это [b]пример[/b] работы парсера [url=https://github.com/Gemorroj/xBBCode]xBBCode[/url].
Expand Down

0 comments on commit 42796b3

Please sign in to comment.