dotnet/roslyn
Roslyn compiler does not round-trip attribute arguments that contain unmatched surrogates
Aperta
#41.764 aperta il 18 feb 2020
Area-CompilersBughelp wanted
Metriche repository
- Star
- (20.414 stelle)
- Metriche merge PR
- (Merge medio 6g 17h) (256 PR mergiate in 30 g)
Descrizione
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");
}