Skip to content

Commit

Permalink
Match attribute values in a case-insensitive manner.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishow committed Dec 24, 2023
1 parent d99d35f commit db835bf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ protected function convertSingleSelector(string $css):string {
$hasElement = true;
}

$currentThreadItem['content'] = strtolower($currentThreadItem['content']);

/** @var null|array<int, array<string, string>> $detail */
$detail = $currentThreadItem["detail"] ?? null;
$detailType = $detail[0] ?? null;
Expand Down
41 changes: 41 additions & 0 deletions test/phpunit/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,47 @@ public function testAttribute() {
);
}

public function testCaseSensitivity() {
$document = new DOMDocument("1.0", "UTF-8");
$document->loadHTML("<div data-FOO='bar'>baz</div>");

$xpath = new DOMXPath($document);


$attributeNameIsCaseInsensitive = new Translator(
"[data-FOO='bar']"
);
self::assertEquals(
1,
$xpath->query($attributeNameIsCaseInsensitive)->length
);

$attributeNameCaseInsensitive = new Translator(
"[data-foo='bar']"
);
self::assertEquals(
1,
$xpath->query($attributeNameCaseInsensitive)->length
);

$attributeValueCaseSensitive = new Translator(
"[data-foo='bar']"
);
self::assertEquals(
1,
$xpath->query($attributeValueCaseSensitive)->length
);

$attributeValueCaseSensitive = new Translator(
"[data-foo='BAR']"
);
self::assertEquals(
0,
$xpath->query($attributeValueCaseSensitive)->length
);

}

public function testAttributeStarSelector() {
$document = new DOMDocument("1.0", "UTF-8");
$document->loadHTML(Helper::HTML_COMPLEX);
Expand Down

0 comments on commit db835bf

Please sign in to comment.