Skip to content

Fix invalid "yyy" format processing for DateTime parse #115507

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

Closed

Conversation

Maximys
Copy link
Contributor

@Maximys Maximys commented May 13, 2025

Current PR fixes #51860 issue

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 13, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 13, 2025
@huoyaoyuan huoyaoyuan added area-System.DateTime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 13, 2025
Copy link
Member

@huoyaoyuan huoyaoyuan left a comment

Choose a reason for hiding this comment

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

The desired behavior hasn't been confirmed by the area owner.

@@ -1,4 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00

Copy link
Member

Choose a reason for hiding this comment

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

Don't commit changes to solution files. They are auto generated and owned by infrastructure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I don't known about it. Reverted by 1f62c3a , but current solution does not build from VS without this change.

@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
Copy link
Member

Choose a reason for hiding this comment

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

Avoid BOM changes for existing files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by 89425c2

@@ -4055,7 +4057,7 @@ private static bool ParseByFormat(
{
parseInfo.fUseTwoDigitYear = true;
}
parseResult = ParseDigits(ref str, tokenLen, out tempYear);
parseResult = ParseDigits(ref str, tokenLen, maxYearTokenLength, out tempYear);
}
Copy link
Member

Choose a reason for hiding this comment

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

parseResult = ParseDigits(ref str, tokenLen, maxDigitLen: tokenLen <= 2 ? 2 : 4, out tempYear);

Copy link
Member

Choose a reason for hiding this comment

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

I think the test https://helixr1107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-115507-merge-c1d147295e6d448da4/System.Net.Http.Functional.Tests/3/console.a9f6f133.log?helixlogtype=result failed because you didn't handle the token length 2. Try the suggestion and let's see if this test will still fail.

@@ -4028,6 +4028,8 @@ private static bool ParseByFormat(
DateTimeFormatInfo dtfi,
scoped ref DateTimeResult result)
{
const int maxYearTokenLength = 4;
Copy link
Member

Choose a reason for hiding this comment

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

const int maxYearTokenLength = 4;

no need to declare this as we use the parameter name in the calling site.

@tarekgh
Copy link
Member

tarekgh commented May 13, 2025

Thinking more, I think this change can break other cases today like parsing yyyMMdd. Let's avoid this break and fix the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.DateTime 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.

DateTime.ParseExact handles "yyy" incorrectly.
3 participants