Skip to content

Commit dbbbfdd

Browse files
committed
Fix decoding url-encoded tags containing 32bits Unicode
1 parent b2b49c1 commit dbbbfdd

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

YamlDotNet/Core/Scanner.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ private Token ScanFlowScalar(bool isSingleQuoted)
16801680

16811681
if (codeLength > 0)
16821682
{
1683-
uint character = 0;
1683+
int character = 0;
16841684

16851685
// Scan the character value.
16861686

@@ -1690,7 +1690,7 @@ private Token ScanFlowScalar(bool isSingleQuoted)
16901690
{
16911691
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a quoted scalar, did not find expected hexdecimal number.");
16921692
}
1693-
character = (uint)((character << 4) + analyzer.AsHex(k));
1693+
character = ((character << 4) + analyzer.AsHex(k));
16941694
}
16951695

16961696
// Check the value and write the character.
@@ -1700,7 +1700,7 @@ private Token ScanFlowScalar(bool isSingleQuoted)
17001700
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a quoted scalar, find invalid Unicode character escape code.");
17011701
}
17021702

1703-
value.Append((char)character);
1703+
value.Append(char.ConvertFromUtf32(character));
17041704

17051705
// Advance the pointer.
17061706

@@ -2170,7 +2170,7 @@ private string ScanTagUri(string head, Mark start)
21702170
/// Decode an URI-escape sequence corresponding to a single UTF-8 character.
21712171
/// </summary>
21722172

2173-
private char ScanUriEscapes(Mark start)
2173+
private string ScanUriEscapes(Mark start)
21742174
{
21752175
// Decode the required number of characters.
21762176

@@ -2223,14 +2223,14 @@ private char ScanUriEscapes(Mark start)
22232223
}
22242224
while (--width > 0);
22252225

2226-
var characters = Encoding.UTF8.GetChars(charBytes.ToArray());
2226+
var result = Encoding.UTF8.GetString(charBytes.ToArray());
22272227

2228-
if (characters.Length != 1)
2228+
if (result.Length == 0 || result.Length > 2)
22292229
{
22302230
throw new SyntaxErrorException(start, cursor.Mark(), "While parsing a tag, find an incorrect UTF-8 sequence.");
22312231
}
22322232

2233-
return characters[0];
2233+
return result;
22342234
}
22352235

22362236
/// <summary>

0 commit comments

Comments
 (0)