dotnet/roslyn
Roslyn compiler does not round-trip attribute arguments that contain unmatched surrogates
Ouverte
#41 764 ouverte le 18 févr. 2020
Area-CompilersBughelp wanted
Métriques du dépôt
- Stars
- (20 414 étoiles)
- Métriques de merge PR
- (Merge moyen 6j 17h) (256 PRs mergées en 30 j)
Description
See also https://github.com/dotnet/roslyn/issues/41280
The following test passes on netcore 3.1, but the test demonstrates that
- an attribute in source with a string argument containing an unmatched surrogate is seen properly (unedited) through the symbol APIs from the source assembly
- results in a different attribute value when viewed through the compiler APIs on the emitted assembly
- results in a yet different value when viewed at runtime using reflection
The same value should be seen through all three mechanisms.
[Fact]
public void TEMP()
{
const string UnicodeHighSurrogate = "\uD800";
const string UnicodeReplacementCharacter = "\uFFFD";
var source =
@"using System;
[Obsolete(UnicodeHighSurrogate)]
class C
{
public const string UnicodeHighSurrogate = ""\uD800"";
public const string UnicodeReplacementCharacter = ""\uFFFD"";
static void Main()
{
string message = ((ObsoleteAttribute)typeof(C).GetCustomAttributes(false)[0]).Message;
Console.WriteLine(message == UnicodeReplacementCharacter + UnicodeReplacementCharacter);
}
}";
Func<bool, Action<ModuleSymbol>> validator = isFromSource => (ModuleSymbol module) =>
{
var C = module.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
var obs = C.GetAttributes()[0];
var tc = obs.ConstructorArguments.First();
Assert.Equal(isFromSource ? UnicodeHighSurrogate : UnicodeReplacementCharacter + UnicodeReplacementCharacter + UnicodeReplacementCharacter, (string)tc.Value);
};
CompileAndVerify(source, sourceSymbolValidator: validator(true), symbolValidator: validator(false), expectedOutput: "True");
}