forked from dotnet/msbuild
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MaybeAdjustFilePath should not collapse multiple slashes
This ends up destroying data that contains double slashes, like URLs Resolves dotnet#1622
- Loading branch information
Showing
2 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/XMakeBuildEngine/UnitTests/Evaluation/EvaluatorFileNormalization_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
//----------------------------------------------------------------------- | ||
// </copyright> | ||
// <summary>Tests for evaluation</summary> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Xml; | ||
|
||
using Microsoft.Build.Collections; | ||
using Microsoft.Build.Construction; | ||
using Microsoft.Build.Evaluation; | ||
using Microsoft.Build.Execution; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Shared; | ||
using Xunit; | ||
|
||
using InvalidProjectFileException = Microsoft.Build.Exceptions.InvalidProjectFileException; | ||
using ProjectHelpers = Microsoft.Build.UnitTests.BackEnd.ProjectHelpers; | ||
|
||
namespace Microsoft.Build.UnitTests.Evaluation | ||
{ | ||
/// <summary> | ||
/// Tests mainly for how evaluation normalizes input for cross-platform paths | ||
/// </summary> | ||
public class EvaluatorFileNormalization_Tests : IDisposable | ||
{ | ||
public EvaluatorFileNormalization_Tests() | ||
{ | ||
ProjectCollection.GlobalProjectCollection.UnloadAllProjects(); | ||
GC.Collect(); | ||
} | ||
|
||
/// <summary> | ||
/// Cleanup | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
ProjectCollection.GlobalProjectCollection.UnloadAllProjects(); | ||
GC.Collect(); | ||
} | ||
|
||
/// <summary> | ||
/// Basic verification -- with TreatAsLocalProperty set, but to a different property than is being passed as a global, the | ||
/// global property overrides the local property. | ||
/// </summary> | ||
[Fact] | ||
public void MultipleForwardSlashesShouldNotGetCollapsedWhenPathLooksLikeUnixPath() | ||
{ | ||
string content = ObjectModelHelpers.CleanupFileContents(@" | ||
<Project> | ||
<PropertyGroup> | ||
<P>/tmp/a//x\\c;ba://</P> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<I Include=""$(p)""/> | ||
</ItemGroup> | ||
<Target Name=""Build""> | ||
<ItemGroup> | ||
<T Include=""$(p)""/> | ||
</ItemGroup> | ||
<Message Text=""GP[$(GP)]"" Importance=""High""/> | ||
<Message Text=""P[$(P)]"" Importance=""High""/> | ||
<Message Text=""I[@(I)]"" Importance=""High""/> | ||
<Message Text=""T[@(T)]"" Importance=""High""/> | ||
</Target> | ||
</Project>"); | ||
|
||
|
||
IDictionary<string, string> globalProperties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | ||
globalProperties.Add("GP", @"/tmp/a//x\\c;ba://"); | ||
|
||
Project project = new Project(XmlReader.Create(new StringReader(content)), globalProperties, null); | ||
|
||
MockLogger logger = new MockLogger(); | ||
bool result = project.Build(logger); | ||
Assert.Equal(true, result); | ||
|
||
var expectedString = NativeMethodsShared.IsWindows ? @"/tmp/a//x\\c;ba://" : @"/tmp/a//x//c;ba://"; | ||
|
||
logger.AssertLogContains($"GP[{expectedString}]"); | ||
logger.AssertLogContains($"P[{expectedString}]"); | ||
logger.AssertLogContains($"I[{expectedString}]"); | ||
logger.AssertLogContains($"T[{expectedString}]"); | ||
|
||
Assert.Equal(expectedString, project.GetPropertyValue("GP")); | ||
Assert.Equal(expectedString, project.GetPropertyValue("P")); | ||
Assert.Equal(expectedString, string.Join(";", project.Items.Select(i => i.EvaluatedInclude))); | ||
} | ||
} | ||
} |