Skip to content

Use default if no value was bound for parameter #39427

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

Merged
merged 1 commit into from
Jan 11, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ private Task BindArgumentsAsync()
{
var parameterInfo = declaredParameterInfos[index];

if (!actionParameters.TryGetValue(parameterInfo.Name!, out var value))
if (!actionParameters.TryGetValue(parameterInfo.Name!, out var value) || value is null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change feels innocuous enough, but do we know why this is needed? The code around here hasn't changed in ages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original issue reported the regression between .NET 5 and .NET 6. I was able to verify it as well. A quick peruse of the commit logs has me suspicious about some of the nullability changes that we made in this area for 6.0-preview4 but I, admittedly, haven't dug deeper. 🤷🏽‍♀️

{
value = actionMethodExecutor.GetDefaultValueForParameter(index);
}
Expand Down
14 changes: 14 additions & 0 deletions src/Mvc/test/Mvc.FunctionalTests/DefaultValuesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,18 @@ public async Task Controller_WithDefaultParameterValues_ForStructs_ReturnsBoundV
// Assert
Assert.Equal(expected, response);
}

[Fact]
public async Task EchoValue_DefaultParameterValue_ForGlobbedPath()
{
// Arrange
var expected = $"index.html";
var url = "http://localhost/DefaultValues/EchoValue_DefaultParameterValue_ForGlobbedPath";

// Act
var response = await Client.GetStringAsync(url);

// Assert
Assert.Equal(expected, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ public string EchoValue_DefaultParameterValue_ForStructs(
{
return $"{guid}, {timeSpan}";
}

[HttpGet]
[Route("/[controller]/EchoValue_DefaultParameterValue_ForGlobbedPath/{**path}")]
public string EchoValue_DefaultParameterValue_ForGlobbedPath(string path = "index.html")
{
return path;
}
}