Skip to content

Commit 9709e11

Browse files
committed
Escape invalid characters in assembly names
1 parent 3edcf21 commit 9709e11

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Authoring/WinRT.SourceGenerator/Generator.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,22 @@ public static void GenerateWinRTExportsType(GeneratorExecutionContext context)
292292
return;
293293
}
294294

295+
// Make sure to escape invalid characters for namespace names.
296+
// See ECMA 335, II.6.2 and II.5.2/3.
297+
if (assemblyName.AsSpan().IndexOfAny("$@`?".AsSpan()) != -1)
298+
{
299+
char[] buffer = new char[assemblyName.Length];
300+
301+
for (int i = 0; i < assemblyName.Length; i++)
302+
{
303+
buffer[i] = assemblyName[i] is '$' or '@' or '`' or '?'
304+
? '_'
305+
: assemblyName[i];
306+
}
307+
308+
assemblyName = new string(buffer);
309+
}
310+
295311
context.AddSource("ExportsType.g.cs", $$"""
296312
// <auto-generated/>
297313
#pragma warning disable

0 commit comments

Comments
 (0)