Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Rule/AnchorSuspiciousLinkText.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ public function id()
public function check()
{
foreach ($this->getAllElements('a') as $a) {
if ((in_array(strtolower(trim($a->nodeValue)), $this->translation()) || $a->nodeValue == $a->getAttribute('href')) && $a->getAttribute('href') != "")

// Check to see if the link text is a url
$textIsLink = ($a->nodeValue == $a->getAttribute('href')) || str_starts_with($a->nodeValue, "http");

// Check that the link is not an anchor
$linkIsAnchor = ($a->getAttribute('href') == "");

if ((in_array(strtolower(trim($a->nodeValue)), $this->translation()) || $textIsLink) && !$linkIsAnchor )
$this->setIssue($a);
$this->totalTests++;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/AnchorSuspiciousLinkTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ public function testCheckTrueAnchorCase()

$this->assertEquals(0, $rule->check(), 'Anchor Suspicious Link Test should have no issues.');
}

/**
* Checks the case where the link text starts with https
*/
public function testCheckFalseTextIsLinkCase()
{
$html = '<div><p><a href="https://cnn.com">https://msn.com</a></p></div>';
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadHTML($html);
$rule = new AnchorSuspiciousLinkText($dom);

$this->assertEquals(0, $rule->check(), 'Anchor Suspicious Link Test should have no issues.');
}
}