WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
142932
CSS Selectors: fix attribute case-insensitive matching of Contain and List
https://bugs.webkit.org/show_bug.cgi?id=142932
Summary
CSS Selectors: fix attribute case-insensitive matching of Contain and List
Benjamin Poulain
Reported
2015-03-20 21:14:59 PDT
CSS Selectors: fix attribute case-insensitive matching of Contain and List
Attachments
Patch
(10.98 KB, patch)
2015-03-20 21:15 PDT
,
Benjamin Poulain
no flags
Details
Formatted Diff
Diff
Patch
(126.38 KB, patch)
2015-03-22 13:06 PDT
,
Benjamin Poulain
no flags
Details
Formatted Diff
Diff
Patch
(125.32 KB, patch)
2015-03-22 20:16 PDT
,
Benjamin Poulain
no flags
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Benjamin Poulain
Comment 1
2015-03-20 21:15:20 PDT
Created
attachment 249159
[details]
Patch
Benjamin Poulain
Comment 2
2015-03-22 13:06:18 PDT
Created
attachment 249203
[details]
Patch
Darin Adler
Comment 3
2015-03-22 18:28:40 PDT
Comment on
attachment 249203
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=249203&action=review
> Source/WTF/wtf/text/StringCommon.h:421 > +template <typename SearchCharacterType, typename MatchCharacterType> > +size_t findIgnoringASCIICase(const SearchCharacterType* searchCharacters, const MatchCharacterType* matchCharacters, unsigned startOffset, unsigned searchLength, unsigned matchLength)
I think the searchCharacters pointer should be before adding startOffset and this function should add startOffset and we should remove all the "+ startOffset" from the callers.
> Source/WTF/wtf/text/StringCommon.h:424 > + // delta is the number of additional times to test; delta == 0 means test only once. > + unsigned delta = searchLength - matchLength;
Seems we need to assert searchLength >= matchLength.
> Source/WTF/wtf/text/StringCommon.h:433 > + unsigned i = 0; > + // Keep looping until we match. > + while (!equalIgnoringASCIICase(searchCharacters + i, matchCharacters, matchLength)) { > + if (i == delta) > + return notFound; > + ++i; > + } > + return startOffset + i;
I think this should be a for loop: unsigned i; for (i = 0; !equalIgnoringASCIICase(searchCharacters + i, matchCharacters, matchLength); ++i) { if (i == delta) return notFound; } return startOffset + i; But I think we should write it in a more traditional fashion: for (unsigned i = 0; i <= delta; ++i) { if (equalIgnoringASCIICase(searchCharacters + i, matchCharacters, matchLength)) return startOffset + i; } return notFound;
> Source/WTF/wtf/text/StringView.h:108 > + WTF_EXPORT_STRING_API size_t findIgnoringASCIICase(const StringView&, unsigned startOffset) const;
If you have a StringView and want to apply a startOffset it’s just view.substring(startOffset) so it’s not really helpful to have this overload.
> Source/WTF/wtf/text/StringView.h:112 > + WTF_EXPORT_STRING_API bool containsIgnoringASCIICase(const StringView&, unsigned startOffset) const;
If you have a StringView and want to apply a startOffset it’s just view.substring(startOffset) so it’s not really helpful to have this overload.
> Source/WebCore/css/SelectorChecker.cpp:460 > + bool valueContainsSelectorValue; > + if (caseSensitive) > + valueContainsSelectorValue = value.contains(selectorValue); > + else > + valueContainsSelectorValue = value.containsIgnoringASCIICase(selectorValue); > + > + if (!valueContainsSelectorValue || selectorValue.isEmpty()) > return false;
This is strange code. Why call contains when selectorValue is empty? Why not just return first? Then we avoid the whole local variable thing: if (selectorValue.isEmpty()) return false; if (caseSensitive) { if (value.contains(selectorValue)) return false; } else { if (value.containsIgnoringASCIICase(selectorValue)) return false; } And in fact, that’s exactly the coding style used below for Begin and End.
Benjamin Poulain
Comment 4
2015-03-22 19:21:37 PDT
(In reply to
comment #3
)
> > Source/WebCore/css/SelectorChecker.cpp:460 > > + bool valueContainsSelectorValue; > > + if (caseSensitive) > > + valueContainsSelectorValue = value.contains(selectorValue); > > + else > > + valueContainsSelectorValue = value.containsIgnoringASCIICase(selectorValue); > > + > > + if (!valueContainsSelectorValue || selectorValue.isEmpty()) > > return false; > > This is strange code. Why call contains when selectorValue is empty? Why not > just return first? Then we avoid the whole local variable thing:
The reason was that selectorValue.isEmpty() never happens in practice. But you are right, better make this code clean. The CSS JIT does a much better job at making this fast.
Benjamin Poulain
Comment 5
2015-03-22 20:16:07 PDT
Created
attachment 249218
[details]
Patch
WebKit Commit Bot
Comment 6
2015-03-22 22:05:27 PDT
Comment on
attachment 249218
[details]
Patch Clearing flags on attachment: 249218 Committed
r181845
: <
http://trac.webkit.org/changeset/181845
>
WebKit Commit Bot
Comment 7
2015-03-22 22:05:31 PDT
All reviewed patches have been landed. Closing bug.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug