Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
CSS: fix the case-insensitive matching of the attribute selectors Beg…
…in, End and Hyphen

https://bugs.webkit.org/show_bug.cgi?id=142715

Reviewed by Brent Fulgham.

Source/WebCore:

Fix attribute matching with:
-Begin: [a^=b].
-End: [a$=b].
-Hyphen: [a|=b].

Tests: fast/selectors/attribute-endswith-value-matching-is-ascii-case-insensitive.html
       fast/selectors/attribute-hyphen-value-matching-is-ascii-case-insensitive.html
       fast/selectors/attribute-startswith-value-matching-is-ascii-case-insensitive.html

* css/SelectorChecker.cpp:
(WebCore::attributeValueMatches):
I forgot to change CSSSelector::Exact in my last patch.
The tests could not catch that since we use the CSS JIT almost everywhere.

* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::attributeValueBeginsWith):
(WebCore::SelectorCompiler::attributeValueEndsWith):
(WebCore::SelectorCompiler::attributeValueMatchHyphenRule):

Source/WTF:

Add the necessary infrastructure to test startsWith() and endsWith() with
ASCII case-insentive comparisons.

* wtf/text/AtomicString.h:
(WTF::AtomicString::startsWith):
(WTF::AtomicString::startsWithIgnoringASCIICase):
(WTF::AtomicString::endsWith):
(WTF::AtomicString::endsWithIgnoringASCIICase):

* wtf/text/StringCommon.h:
(WTF::loadUnaligned):
(WTF::equal):
I moved the low level equal() code from StringImpl to StringCommon
since it is used by both StringImpl and StringView.

(WTF::equalCommon):
(WTF::equalIgnoringASCIICaseCommon):
Ideally we should drop the "Common" part of the name but StringView
wants this inline for some reason. I prefered keeping the current behavior
since I don't know how StringView's matching performance was evaluated.

(WTF::startsWith):
(WTF::startsWithIgnoringASCIICase):
(WTF::endsWith):
(WTF::endsWithIgnoringASCIICase):
Make all that code shared between StringView and Stringimpl.

* wtf/text/StringImpl.cpp:
(WTF::StringImpl::startsWith):
(WTF::StringImpl::startsWithIgnoringASCIICase):
(WTF::StringImpl::endsWith):
(WTF::StringImpl::endsWithIgnoringASCIICase):
(WTF::equal):
(WTF::stringImplContentEqual): Deleted.
* wtf/text/StringImpl.h:
(WTF::loadUnaligned): Deleted.
(WTF::equal): Deleted.

* wtf/text/StringView.cpp:
(WTF::StringView::startsWith):
(WTF::StringView::startsWithIgnoringASCIICase):
(WTF::StringView::endsWith):
(WTF::StringView::endsWithIgnoringASCIICase):
* wtf/text/StringView.h:
Since those are new, we can safely make them out-of-line and
evaluate the inlining impact as needed.

* wtf/text/WTFString.h:
(WTF::String::startsWithIgnoringASCIICase):
(WTF::String::endsWith):
(WTF::String::endsWithIgnoringASCIICase):

Tools:

* TestWebKitAPI/Tests/WTF/StringImpl.cpp:
(TestWebKitAPI::TEST):

LayoutTests:

* fast/selectors/attribute-endswith-value-matching-is-ascii-case-insensitive-expected.txt: Added.
* fast/selectors/attribute-endswith-value-matching-is-ascii-case-insensitive.html: Added.
* fast/selectors/attribute-hyphen-value-matching-is-ascii-case-insensitive-expected.txt: Added.
* fast/selectors/attribute-hyphen-value-matching-is-ascii-case-insensitive.html: Added.
* fast/selectors/attribute-startswith-value-matching-is-ascii-case-insensitive-expected.txt: Added.
* fast/selectors/attribute-startswith-value-matching-is-ascii-case-insensitive.html: Added.


Canonical link: https://commits.webkit.org/160728@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181525 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
BenjaminPoulain committed Mar 16, 2015
1 parent aa4bf63 commit 80ab7a2
Show file tree
Hide file tree
Showing 20 changed files with 2,291 additions and 324 deletions.
14 changes: 14 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,17 @@
2015-03-15 Benjamin Poulain <benjamin@webkit.org>

CSS: fix the case-insensitive matching of the attribute selectors Begin, End and Hyphen
https://bugs.webkit.org/show_bug.cgi?id=142715

Reviewed by Brent Fulgham.

* fast/selectors/attribute-endswith-value-matching-is-ascii-case-insensitive-expected.txt: Added.
* fast/selectors/attribute-endswith-value-matching-is-ascii-case-insensitive.html: Added.
* fast/selectors/attribute-hyphen-value-matching-is-ascii-case-insensitive-expected.txt: Added.
* fast/selectors/attribute-hyphen-value-matching-is-ascii-case-insensitive.html: Added.
* fast/selectors/attribute-startswith-value-matching-is-ascii-case-insensitive-expected.txt: Added.
* fast/selectors/attribute-startswith-value-matching-is-ascii-case-insensitive.html: Added.

2015-03-15 Brent Fulgham <bfulgham@apple.com>

Scroll snap points are not supported on iframe content
Expand Down

Large diffs are not rendered by default.

@@ -0,0 +1,122 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="../../resources/js-test-pre.js"></script>
<style>
#test-root * {
background-color: red;
}
</style>
<style id="style">
</style>
</head>
<body>
<div style="display:none" id="test-root">
<div data-attribute="Web-É-Kit" multiple="WEB-é-KIT" id="target1"></div>
<div data-attribute="web-É-kit" multiple="Web-é-Kit" id="target2"></div>
<div data-attribute="WEB-É-KIT" multiple="Web-é-kit" id="target3"></div>
<div data-attribute="Web-é-Kit" multiple="web-É-kit" id="target4"></div>
<div data-attribute="web-é-kit" multiple="web-É-Kit" id="target5"></div>
</div>
</body>
<script>
description('When matching attributes case insensitively, it should be ASCII case insensitive. This test verifies the behavior when matching the end of the values (e.g. [a$="b"])');

function testQuerySelector(selector, expectedIds) {
shouldBe("document.querySelectorAll('" + selector + "').length", '' + expectedIds.length);
for (var i = 0; i < expectedIds.length; ++i)
shouldBeEqualToString("document.querySelectorAll('" + selector + "')[" + i + "].id", 'target' + expectedIds[i]);
}

function testStyling(selector, expectedIds) {
var stylingElement = document.getElementById("style");
stylingElement.innerHTML = '' + selector + ' { background-color: rgb(10, 100, 200); }';

var allTestCases = document.querySelectorAll("#test-root *");
for (var i = 0; i < allTestCases.length; ++i) {
var expectMatch = expectedIds.indexOf(parseInt(allTestCases[i].id.replace('target', ''))) >= 0;
shouldBeEqualToString('getComputedStyle(document.querySelectorAll("#test-root *")[' + i + ']).backgroundColor', expectMatch ? 'rgb(10, 100, 200)' : 'rgb(255, 0, 0)');
}

stylingElement.innerHTML = '';
}

function testSelector(selector, expectedIds) {
debug("Testing \"" + selector + "\"");
testQuerySelector("#test-root " + selector, expectedIds);
testStyling("#test-root " + selector, expectedIds);
debug("");
}

var testCases = [
// Regular attribute matching is case sensitive.
['[data-attribute$=Web-É-Kit]', [1]],
['[data-attribute$=É-Kit]', [1]],

['[data-attribute$=web-É-kit]', [2]],
['[data-attribute$=É-kit]', [2]],

['[data-attribute$=WEB-É-KIT]', [3]],
['[data-attribute$=É-KIT]', [3]],

['[data-attribute$=Web-é-Kit]', [4]],
['[data-attribute$=é-Kit]', [4]],

['[data-attribute$=web-é-kit]', [5]],
['[data-attribute$=é-kit]', [5]],

// Same selectors with the case-insensitive flag.
['[data-attribute$=Web-É-Kit i]', [1, 2, 3]],
['[data-attribute$=É-Kit i]', [1, 2, 3]],

['[data-attribute$=web-É-kit i]', [1, 2, 3]],
['[data-attribute$=É-kit i]', [1, 2, 3]],

['[data-attribute$=WEB-É-KIT i]', [1, 2, 3]],
['[data-attribute$=É-KIT i]', [1, 2, 3]],

['[data-attribute$=Web-é-Kit i]', [4, 5]],
['[data-attribute$=é-Kit i]', [4, 5]],

['[data-attribute$=web-é-kit i]', [4, 5]],
['[data-attribute$=é-kit i]', [4, 5]],

// "multiple" is one of those weird legacy exception: it is always case insensitive in HTML.
['[multiple$=WEB-é-KIT]', [1, 2, 3]],
['[multiple$=é-KIT]', [1, 2, 3]],

['[multiple$=Web-é-Kit]', [1, 2, 3]],
['[multiple$=é-Kit]', [1, 2, 3]],

['[multiple$=Web-é-kit]', [1, 2, 3]],
['[multiple$=é-kit]', [1, 2, 3]],

['[multiple$=web-É-kit]', [4, 5]],
['[multiple$=É-kit]', [4, 5]],

['[multiple$=web-É-Kit]', [4, 5]],
['[multiple$=É-Kit]', [4, 5]],

['[multiple$=WEB-é-KIT i]', [1, 2, 3]],
['[multiple$=é-KIT i]', [1, 2, 3]],

['[multiple$=Web-é-Kit i]', [1, 2, 3]],
['[multiple$=é-Kit i]', [1, 2, 3]],

['[multiple$=Web-é-kit i]', [1, 2, 3]],
['[multiple$=é-kit i]', [1, 2, 3]],

['[multiple$=web-É-kit i]', [4, 5]],
['[multiple$=É-kit i]', [4, 5]],

['[multiple$=web-É-Kit i]', [4, 5]],
['[multiple$=É-Kit i]', [4, 5]],
];

for (var testCase of testCases) {
testSelector(testCase[0], testCase[1]);
}
</script>
<script src="../../resources/js-test-post.js"></script>
</html>

0 comments on commit 80ab7a2

Please sign in to comment.