diff --git a/composer.json b/composer.json index b0c7f8e..d5ae740 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "yaknet" ], "homepage": "https://forum.yak.net.tr", - "version": "3.0.4", + "version": "3.0.5", "type": "library", "license": "MIT", "authors": [ diff --git a/demo/test_new_error.html b/demo/test_new_error.html index e86f914..67d6a33 100644 --- a/demo/test_new_error.html +++ b/demo/test_new_error.html @@ -1,9 +1,25 @@ Test Page + - - + Avatar + + Click here for nothing + Do something + + + + + + + + + + +
Header 1Header 2
Data 1Data 2
+ + diff --git a/src/Rules/LabelTargetExists.php b/src/Rules/LabelTargetExists.php new file mode 100644 index 0000000..35a9967 --- /dev/null +++ b/src/Rules/LabelTargetExists.php @@ -0,0 +1,50 @@ +tagName) !== 'label') { + return null; + } + + if ($element->hasAttribute('for')) { + $forId = trim($element->getAttribute('for')); + if ($forId === '') { + return $this->createViolation( + $element, + $this->getDescription(), + 'Provide a valid element ID in the for attribute.' + ); + } + + $doc = $element->ownerDocument; + if ($doc !== null) { + $xpath = new \DOMXPath($doc); + $elements = $xpath->query('//*[@id="' . $forId . '"]'); + if ($elements === false || $elements->length === 0) { + return $this->createViolation( + $element, + $this->getDescription(), + "Ensure the 'for' attribute value (\"$forId\") matches the ID of a form input element." + ); + } + } + } + + return null; + } +} diff --git a/src/Rules/LinkHrefJavascript.php b/src/Rules/LinkHrefJavascript.php new file mode 100644 index 0000000..81da57a --- /dev/null +++ b/src/Rules/LinkHrefJavascript.php @@ -0,0 +1,39 @@ +tagName) !== 'a') { + return null; + } + + if ($element->hasAttribute('href')) { + $href = trim($element->getAttribute('href')); + + // Check for javascript: links or '#' (which represents a placeholder/scripting target) + if (str_starts_with(strtolower($href), 'javascript:') || $href === '#') { + return $this->createViolation( + $element, + $this->getDescription(), + 'Convert the link to a