Skip to content

Validate arguments of Parse(string), New(ReadOnlySpan<byte>) and DefaultGenerationOptions - #126

Merged
Seramis merged 1 commit into
ByteAether:mainfrom
Seramis:validation/argument-validation
Nov 3, 2026
Merged

Seramis merged 1 commit into
ByteAether:mainfrom
Seramis:validation/argument-validation

Conversation

@Seramis

@Seramis Seramis commented Nov 3, 2026

Copy link
Copy Markdown
Member

Description

Parse(string) and the implicit string conversion now throw ArgumentNullException for null instead of a FormatException. DefaultGenerationOptions rejects null in its setter instead of failing with a NullReferenceException on the next Ulid.New().

New(ReadOnlySpan) checks the length explicitly and throws an ArgumentException naming "bytes" and the 16 byte minimum, instead of leaking the internal "length" parameter of MemoryMarshal.Read. Longer input is accepted and only its first 16 bytes are used, which is now documented. None of the changes slows down a hot path.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Other (please specify):

Checklist

  • The PR is submitted to the correct branch (main).
  • My code follows the project's coding style. (.editorconfig)
  • I have commented my code, particularly in hard-to-understand areas and public interfaces.
  • I have added or updated tests for the changes I made.
  • All new and existing tests passed.
  • I have updated the documentation where applicable.

…ultGenerationOptions

Parse(string) and the implicit string conversion now throw ArgumentNullException for null instead of a FormatException. DefaultGenerationOptions rejects null in its setter instead of failing with a NullReferenceException on the next Ulid.New().

New(ReadOnlySpan<byte>) checks the length explicitly and throws an ArgumentException naming "bytes" and the 16 byte minimum, instead of leaking the internal "length" parameter of MemoryMarshal.Read. Longer input is accepted and only its first 16 bytes are used, which is now documented. None of the changes slows down a hot path.
@Seramis Seramis self-assigned this Nov 3, 2026
@Seramis Seramis added enhancement New feature or request pkg:Ulid ByteAether.Ulid .NET Pull requests that update .NET code labels Nov 3, 2026
@Seramis
Seramis merged commit 0fa7b88 into ByteAether:main Nov 3, 2026
5 checks passed
@Seramis
Seramis deleted the validation/argument-validation branch November 3, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request .NET Pull requests that update .NET code pkg:Ulid ByteAether.Ulid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant