Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebCmdlets parse XML declaration to get encoding value, if present. #18748

Merged
merged 10 commits into from
Jan 21, 2023
Prev Previous commit
Next Next commit
add comment
  • Loading branch information
CarloToso committed Dec 8, 2022
commit 282c328d8035a700ad79313704a9ce12b4fe529e
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,16 @@ internal static string DecodeStream(Stream stream, ref Encoding encoding)
string content = StreamToString(stream, encoding);
if (isDefaultEncoding)
{
// check for a charset attribute on the meta element to override the default
// Check for a charset attribute on the meta element to override the default
// we only look within the first 1k characters as the meta tag is in the head
// tag which is at the start of the document
Match match = s_metaRegex.Match(content.Substring(0, Math.Min(content.Length, 1024)));

// Check for a encoding attribute on the xml declaration to override the default
// we only look within the first 256 characters as the declaration is in the first
// line of the document
Match match2 = s_xmlRegex.Match(content.Substring(0, Math.Min(content.Length, 256)));
iSazonov marked this conversation as resolved.
Show resolved Hide resolved

if (match.Success || match2.Success)
{
Encoding localEncoding = null;
Expand Down