Skip to content
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

Fix AntiforgeryMiddlewareTest for non-US date formats #55779

Merged

Conversation

martincostello
Copy link
Member

Fix AntiforgeryMiddlewareTest for non-US date formats

Fix tests failing with HTTP 400 if machine uses a non-US date format.

Description

Use CultureInfo.CurrentCulture to match MVC's default DateTime binding behaviour to fix tests when running on a machine that doesn't use invariant/en-US date formatting, such as en-GB.

Otherwise the line below throws when binding the posted form as the format is invariant but MVC tries to bind it with the current culture.

model = DateTime.Parse(value, valueProviderResult.Culture, _supportedStyles);

I figured this was the simpler change than reconfiguring MVC in all the tests to use invariant binding by default.

See #55595 (comment).

Use `CultureInfo.CurrentCulture` to match MVC's default `DateTime` binding behaviour to fix tests when running on a machine that doesn't use invariant/en-US date formatting, such as en-GB.
@martincostello martincostello requested a review from a team as a code owner May 18, 2024 08:52
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label May 18, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 18, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label May 27, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the 9.0-preview6 milestone May 27, 2024
Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

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

LGTM!

I took a look at the stacktrace for this issue and it looks like prefixing the field names in the tests with __Invariant might also do the trick but this feels more straightforward.

@captainsafia captainsafia merged commit b62acd5 into dotnet:main May 29, 2024
27 checks passed
@captainsafia captainsafia removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label May 29, 2024
@martincostello martincostello deleted the fix-antiforgerymiddleware-tests-enGB branch May 29, 2024 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants