dotnet / dotnet/dotnet-api-docs

Guid.TryParseExact("+0xabbbb-+0xa-+0xb-+0xa-+0xbaaaabbbb", "D", out _) returns true

Open
#5,456 4 comments 0 reactions 0 assignees View on GitHub
area-System.Runtime Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

### Description

Tested with PowerShell 7.1.3, which uses .NET 5.0.4:

```
PS C:\> $g = [Guid]::Empty
PS C:\> [Guid]::TryParseExact("+0xabbbb-+0xa-+0xb-+0xa-+0xbaaaabbbb", "D", [ref]$g)
True
PS C:\> $g

Guid
----
000abbbb-000a-000b-000a-000baaaabbbb

PS C:\>
```

I expect that Guid.TryParseExact should return false because "+0xabbbb-+0xa-+0xb-+0xa-+0xbaaaabbbb" is not in the format that Guid.ToString("D") would return. Guid.TryParseExact should allow "+" and "0x" prefixes only when the `format` argument is "X".

### Configuration

.NET 5.0.4 on Microsoft Windows 10.0.19042 x64

### Regression?

I don't know.

### Other information

Guid.TryParseExactD calls Guid.TryParseHex, which allows these prefixes.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.