Skip to content

Commit

Permalink
Fix encoding and disposing
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKrivanek committed Jun 22, 2023
1 parent cb24717 commit bdd0ad7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand Down Expand Up @@ -46,7 +46,7 @@ internal new string[] DefaultPaths
/// </summary>
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("\uE025\uE026")]
public void Exists(string appConfigNameSuffix)
{
// Create the engine.
Expand Down
7 changes: 4 additions & 3 deletions src/Tasks/AppConfig/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ internal void Load(string appConfigFile)
XmlReader reader = null;
try
{
var readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore };
var readerSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true};

// it's important to normalize the path as it may contain two slashes
// see https://github.com/dotnet/msbuild/issues/4335 for details.
appConfigFile = FileUtilities.NormalizePath(appConfigFile);

// Need a filestream as the XmlReader doesn't support nonstandard unicode characters in path
using FileStream fs = File.OpenRead(appConfigFile);
// Need a filestream as the XmlReader doesn't support nonstandard unicode characters in path.
// No need to dispose - as 'CloseInput' was passed to XmlReaderSettings
FileStream fs = File.OpenRead(appConfigFile);
reader = XmlReader.Create(fs, readerSettings);
Read(reader);
}
Expand Down

0 comments on commit bdd0ad7

Please sign in to comment.