From 1a88f9d8f4db6be5ec3f856ae3261e02eae957a9 Mon Sep 17 00:00:00 2001 From: JonathanCrandall <103459074+JonathanCrandall@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:43:18 -0700 Subject: [PATCH] added check for http at the start of link text --- src/Rule/AnchorSuspiciousLinkText.php | 9 ++++++++- tests/AnchorSuspiciousLinkTextTest.php | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Rule/AnchorSuspiciousLinkText.php b/src/Rule/AnchorSuspiciousLinkText.php index 0076587..e139590 100644 --- a/src/Rule/AnchorSuspiciousLinkText.php +++ b/src/Rule/AnchorSuspiciousLinkText.php @@ -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++; } diff --git a/tests/AnchorSuspiciousLinkTextTest.php b/tests/AnchorSuspiciousLinkTextTest.php index 195af70..d1e1fcd 100644 --- a/tests/AnchorSuspiciousLinkTextTest.php +++ b/tests/AnchorSuspiciousLinkTextTest.php @@ -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 = '
'; + $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.'); + } } \ No newline at end of file