Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/BannedSymbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ M:System.Xml.XmlReader.Create(System.String,System.Xml.XmlReaderSettings);Do not
M:System.Xml.XmlReader.Create(System.String,System.Xml.XmlReaderSettings,System.Xml.XmlParserContext);Do not pass paths to XmlReader.Create--use the Stream overload
M:System.Xml.XPath.XPathDocument.#ctor(System.String);Do not pass string paths to XPathDocument ctor--use the Stream overload
M:System.Xml.XPath.XPathDocument.#ctor(System.String,System.Xml.XmlSpace);Do not pass string paths to XPathDocument ctor--use the Stream overload
M:System.Xml.Linq.XDocument.Load(System.String);Do not pass uri to XDocument.Load, use overload with XmlReader instead
M:System.Xml.Linq.XDocument.Load(System.String, System.Xml.Linq.LoadOptions);Do not pass uri to XDocument.Load, use overload with XmlReader instead
9 changes: 8 additions & 1 deletion src/Shared/UnitTests/TestAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Xml;
using System.Xml.Linq;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;
Expand Down Expand Up @@ -103,7 +104,13 @@ private static void SetDotnetHostPath(TestEnvironment testEnvironment)
string potentialVersionsPropsPath = Path.Combine(currentFolder, "build", "Versions.props");
if (FileSystems.Default.FileExists(potentialVersionsPropsPath))
{
var doc = XDocument.Load(potentialVersionsPropsPath);
XDocument doc = null;
var xrs = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true, IgnoreWhitespace = true };
using (XmlReader xr = XmlReader.Create(File.OpenRead(potentialVersionsPropsPath), xrs))
{
doc = XDocument.Load(xr);
}

var ns = doc.Root.Name.Namespace;
var cliVersionElement = doc.Root.Elements(ns + "PropertyGroup").Elements(ns + "DotNetCliVersion").FirstOrDefault();
if (cliVersionElement != null)
Expand Down
25 changes: 21 additions & 4 deletions src/Tasks.UnitTests/GenerateBindingRedirects_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,22 @@ public void AppConfigInvalidIfDependentAssemblyNodeIsEmpty()
redirectResults.Engine.AssertLogContains("MSB3835");
}

[Fact]
public void AppConfigWhenFilePlacedInLocationWithGB18030Characters()
{
using (TestEnvironment env = TestEnvironment.Create())
{
TransientTestFolder rootTestFolder = env.CreateFolder();
TransientTestFolder testFolder = env.CreateFolder(Path.Combine(rootTestFolder.Path, "\uD873\uDD02\u9FA8\u82D8\u722B\u9EA4\u03C5\u33D1\uE038\u486B\u0033"));
string appConfigContents = WriteAppConfigRuntimeSection(string.Empty, testFolder);
string outputAppConfigFile = env.ExpectFile(".config").Path;

TaskItemMock redirect = new TaskItemMock("System, Version=10.0.0.0, Culture=Neutral, PublicKeyToken='b77a5c561934e089'", "40.0.0.0");

_ = Should.NotThrow(() => GenerateBindingRedirects(appConfigContents, outputAppConfigFile, redirect));
}
}

[Fact]
public void AppConfigFileNotSavedWhenIdentical()
{
Expand Down Expand Up @@ -306,12 +322,11 @@ private BindingRedirectsExecutionResult GenerateBindingRedirects(string appConfi
GenerateBindingRedirects bindingRedirects = new GenerateBindingRedirects
{
BuildEngine = engine,
SuggestedRedirects = suggestedRedirects ?? System.Array.Empty<ITaskItem>(),
SuggestedRedirects = suggestedRedirects ?? Array.Empty<ITaskItem>(),
AppConfigFile = new TaskItem(appConfigFile),
OutputAppConfigFile = new TaskItem(outputAppConfig)
};


bool executionResult = bindingRedirects.Execute();

return new BindingRedirectsExecutionResult
Expand All @@ -324,7 +339,9 @@ private BindingRedirectsExecutionResult GenerateBindingRedirects(string appConfi
};
}

private string WriteAppConfigRuntimeSection(string runtimeSection)
private string WriteAppConfigRuntimeSection(
string runtimeSection,
TransientTestFolder transientTestFolder = null)
{
string formatString =
@"<configuration>
Expand All @@ -334,7 +351,7 @@ private string WriteAppConfigRuntimeSection(string runtimeSection)
</configuration>";
string appConfigContents = string.Format(formatString, runtimeSection);

string appConfigFile = _env.CreateFile(".config").Path;
string appConfigFile = _env.CreateFile(transientTestFolder ?? new TransientTestFolder(), ".config").Path;
File.WriteAllText(appConfigFile, appConfigContents);
return appConfigFile;
}
Expand Down
8 changes: 7 additions & 1 deletion src/Tasks/AssemblyDependency/GenerateBindingRedirects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;
using System.IO;
using System.Xml;

#nullable disable

Expand Down Expand Up @@ -335,7 +336,12 @@ private XDocument LoadAppConfig(ITaskItem appConfigItem)
}
else
{
document = XDocument.Load(appConfigItem.ItemSpec);
var xrs = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, CloseInput = true, IgnoreWhitespace = true };
using (XmlReader xr = XmlReader.Create(File.OpenRead(appConfigItem.ItemSpec), xrs))
{
document = XDocument.Load(xr);
}

if (document.Root == null || document.Root.Name != "configuration")
{
Log.LogErrorWithCodeFromResources("GenerateBindingRedirects.MissingConfigurationNode");
Expand Down