fix(ivy): match class and attribute value without case-sensitivity (#32548)
Prior to this commit, a directive with a selector `selector=".Titledir"` would not match an element like `div class="titleDir"` in Ivy whereas it would in VE. The same issue was present for `selector="[title=Titledir]` and `title="titleDir"`. This fixes the Ivy behavior by changing the matching algorithm to use lowercased values. Note that some `render3` tests needed to be changed to reflect that the compiler generates lowercase selectors. These tests are in the process to be migrated to `acceptance` to use `TestBed` in another PR anyway. PR Close #32548
This commit is contained in:

committed by
Matias Niemelä

parent
8a6e54a06d
commit
ded57245e1
@ -21,7 +21,10 @@ const NG_TEMPLATE_SELECTOR = 'ng-template';
|
||||
|
||||
function isCssClassMatching(nodeClassAttrVal: string, cssClassToMatch: string): boolean {
|
||||
const nodeClassesLen = nodeClassAttrVal.length;
|
||||
const matchIndex = nodeClassAttrVal !.indexOf(cssClassToMatch);
|
||||
// we lowercase the class attribute value to be able to match
|
||||
// selectors without case-sensitivity
|
||||
// (selectors are already in lowercase when generated)
|
||||
const matchIndex = nodeClassAttrVal.toLowerCase().indexOf(cssClassToMatch);
|
||||
const matchEndIdx = matchIndex + cssClassToMatch.length;
|
||||
if (matchIndex === -1 // no match
|
||||
|| (matchIndex > 0 && nodeClassAttrVal ![matchIndex - 1] !== ' ') // no space before
|
||||
@ -132,7 +135,10 @@ export function isNodeMatchingSelector(
|
||||
ngDevMode && assertNotEqual(
|
||||
nodeAttrs[attrIndexInNode], AttributeMarker.NamespaceURI,
|
||||
'We do not match directives on namespaced attributes');
|
||||
nodeAttrValue = nodeAttrs[attrIndexInNode + 1] as string;
|
||||
// we lowercase the attribute value to be able to match
|
||||
// selectors without case-sensitivity
|
||||
// (selectors are already in lowercase when generated)
|
||||
nodeAttrValue = (nodeAttrs[attrIndexInNode + 1] as string).toLowerCase();
|
||||
}
|
||||
|
||||
const compareAgainstClassName = mode & SelectorFlags.CLASS ? nodeAttrValue : null;
|
||||
|
Reference in New Issue
Block a user