Skip to content

Commit 92c084d

Browse files
authored
Fix matching of Clutz-renamed types against allowed type names. (#288)
1 parent 5eaf910 commit 92c084d

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/lit-analyzer/src/lib/rules/util/type/is-assignable-binding-under-security-system.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function matchesAtLeastOneNominalType(typeNames: string[], typeB: SimpleType): b
112112
return true;
113113
}
114114
const normalized = normalizeTypeName(typeBName);
115-
if (normalized !== undefined && typeNames.includes(typeBName)) {
115+
if (normalized !== undefined && typeNames.includes(normalized)) {
116116
return true;
117117
}
118118
}

packages/lit-analyzer/src/test/rules/security-system.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,29 @@ tsTest(testName, t => {
169169
const { diagnostics } = getDiagnostics(preface + "html`<div .style=${anyValue}></div>`", { securitySystem: "ClosureSafeTypes" });
170170
hasNoDiagnostics(t, diagnostics);
171171
});
172+
173+
testName = "Types renamed by Clutz are properly matched against allowed types.";
174+
tsTest(testName, t => {
175+
const { diagnostics } = getDiagnostics(
176+
[
177+
{
178+
fileName: "main.ts",
179+
text: `
180+
// A type name known to have been output by Clutz.
181+
class module$contents$goog$html$SafeUrl_SafeUrl {}
182+
183+
html\`<a href='\${"abc" as module$contents$goog$html$SafeUrl_SafeUrl}'>This is a link.</a>\`;
184+
185+
// A type name of the same format.
186+
class module$some$clutz$name_TrustedResourceUrl {}
187+
188+
html\`<script src='\${"abc" as module$some$clutz$name_TrustedResourceUrl}'></script>\`;
189+
`
190+
}
191+
],
192+
{
193+
securitySystem: "ClosureSafeTypes"
194+
}
195+
);
196+
hasNoDiagnostics(t, diagnostics);
197+
});

0 commit comments

Comments
 (0)