Repository navigation
Fix Version.Parse to show original input in FormatException message when input has trailing dots - #121055
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-runtime |
…or trailing dots Co-authored-by: stephentoub <[email protected]>
Copilot
AI
changed the title
[WIP] Fix empty parameter value in FormatException for Version.Parse
Fix Oct 24, 2025
Version.Parse to show original input in FormatException message when input has trailing dots
stephentoub
reviewed
Oct 24, 2025
lilinus
reviewed
Oct 24, 2025
stephentoub
reviewed
Oct 25, 2025
…add UTF8 invalid byte tests Co-authored-by: stephentoub <[email protected]>
stephentoub
reviewed
Oct 26, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where Version.Parse displayed an empty string in error messages when parsing failed due to trailing dots (e.g., "1.0."). The fix ensures the original input string is included in FormatException messages for better diagnostics.
Key Changes:
- Modified
TryParseComponentto accept and use the original input string for error messages - Refactored error handling to use non-throwing
TryParseBinaryIntegerStylefor better performance - Added comprehensive test coverage for trailing dot scenarios and invalid UTF8 sequences
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Version.cs | Updated TryParseComponent to accept original input parameter and refactored exception throwing to a [DoesNotReturn] static local function |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/VersionTests.cs | Added tests for trailing dots with string/span/UTF8 inputs and invalid UTF8 byte sequences |
Member
|
@EgorBot -amd -intel -arm using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkSwitcher.FromAssembly(typeof(Benchmarks).Assembly).Run(args);
public class Benchmarks
{
[Benchmark]
[Arguments("1.2")]
[Arguments("123.123.123.123")]
public Version Parse(string s) => Version.Parse(s);
} |
Member
|
@EgorBo, looks like your bot might need to bump some version numbers? |
Co-authored-by: stephentoub <[email protected]>
stephentoub
approved these changes
Oct 26, 2025
stephentoub
enabled auto-merge (squash)
October 26, 2025 02:42
Member
Co-authored-by: stephentoub <[email protected]>
auto-merge was automatically disabled
October 26, 2025 03:21
Head branch was pushed to by a user without write access
This was referenced Oct 26, 2025
Open
stephentoub
approved these changes
Oct 27, 2025
tannergooding
approved these changes
Nov 20, 2025
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed
Version.Parseto include the original input string inFormatExceptionmessages when parsing fails due to trailing dots or empty components.Changes:
TryParseComponentto accept original input parameterNumber.TryParseBinaryIntegerStylepath for better performance[DoesNotReturn]static local functionThrowIfNegativealready performs the checkVerification:
Original prompt
Fixes #115612
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.