Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
50 changes: 50 additions & 0 deletions src/Build.UnitTests/Evaluation/Expander_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4978,6 +4978,56 @@ public void ExpandItem_ConvertToStringUsingInvariantCultureForNumberData_Respect
}
}

[Theory]
[InlineData("getType")]
[InlineData("GetType")]
[InlineData("gettype")]
public void GetTypeMethod_ShouldNotBeAllowed(string methodName)
{
using (var env = TestEnvironment.Create())
{
var root = env.CreateFolder();

var projectFile = env.CreateFile(root, ".proj",
@$"<Project>
<PropertyGroup>
<foo>aa</foo>
<typeval>$(foo.{methodName}().FullName)</typeval>
</PropertyGroup>
</Project>");
var exception = Should.Throw<InvalidProjectFileException>(() =>
{
new ProjectInstance(projectFile.Path);
});
exception.BaseMessage.ShouldContain($"The function \"{methodName}\" on type \"System.String\" is not available for execution as an MSBuild property function.");
}
}

[Theory]
[InlineData("getType")]
[InlineData("GetType")]
[InlineData("gettype")]
public void GetTypeMethod_ShouldBeAllowed_EnabledByEnvVariable(string methodName)
{
using (var env = TestEnvironment.Create())
{
env.SetEnvironmentVariable("MSBUILDENABLEALLPROPERTYFUNCTIONS", "1");
var root = env.CreateFolder();

var projectFile = env.CreateFile(root, ".proj",
@$"<Project>
<PropertyGroup>
<foo>aa</foo>
<typeval>$(foo.{methodName}().FullName)</typeval>
</PropertyGroup>
</Project>");
Should.NotThrow(() =>
{
new ProjectInstance(projectFile.Path);
});
}
}

/// <summary>
/// Determines if ICU mode is enabled.
/// Copied from: https://learn.microsoft.com/en-us/dotnet/core/extensions/globalization-icu#determine-if-your-app-is-using-icu
Expand Down
2 changes: 1 addition & 1 deletion src/Build/Evaluation/Expander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5308,7 +5308,7 @@ private static bool IsInstanceMethodAvailable(string methodName)
}

// This could be expanded to an allow / deny list.
return methodName != "GetType";
return !string.Equals("GetType", methodName, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
Expand Down