Closed RamType0 closed 2 years ago
Throw an exception when converting invalid strings to UTF-8, such as those containing unpaired surrogates.
[Fact]
public unsafe void UnpairedSurrogateComparison()
{
// "\ufffd" == "�" It is the default fallback character for UTF8Encoding
const string FallbackCharStr = "\ufffd";
// "\ud83d" is one of the surrogate
const string SurrogateCharStr = "\ud83d";
var fallbackCharUtf8Bytes = UTF8ExceptionFallbackEncoding.Instance.GetBytes(FallbackCharStr);
fixed(byte* ptr = fallbackCharUtf8Bytes) {
var fallbackCharRawStr = new RawString(ptr, fallbackCharUtf8Bytes.Length);
Assert.Throws<EncoderFallbackException>(() => fallbackCharRawStr.StartsWith(SurrogateCharStr));
Assert.Throws<EncoderFallbackException>(() => fallbackCharRawStr.EndsWith(SurrogateCharStr));
}
}
RawString.StartsWith
andRawString.EndsWith
treats any unpaired surrogate in argument string as "�". So...This kind of test fails.