Skip to content

Validate enum values parsed from numeric strings in SqliteConnectionStringBuilder - #39654

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlite-connection-string-undefined-enum-value
Nov 17, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlite-connection-string-undefined-enum-value

Conversation

@ilkertskn

Copy link
Copy Markdown
Contributor

ConvertToEnum returned Enum.Parse's result for strings without the Enum.IsDefined check applied to every other input. Enum.Parse accepts numeric strings and comma-separated names, so "Mode=42", "Cache=42" or "Synchronous=7" were accepted, while the integer 42 was rejected.

An undefined Mode silently opened the database as ReadWriteCreate (and failed a Debug.Assert), an undefined Cache was ignored, and an undefined Synchronous value was sent as PRAGMA synchronous.

Run the string result through the same validation.

  • [x ] I've read the guidelines for contributing and seen the walkthrough
  • [ x] I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • [x ] The code builds and tests pass locally (also verified by our automated build checks)
  • [x ] Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • [x ] Tests for the changes have been added (for bug fixes / features)
  • [x ] Code follows the same patterns and style as existing code in this repo

…lder

ConvertToEnum returned Enum.Parse's result for strings without the
Enum.IsDefined check applied to every other input. Enum.Parse accepts
numeric strings and comma-separated names, so "Mode=42", "Cache=42" or
"Synchronous=7" were accepted, while the integer 42 was rejected.

An undefined Mode silently opened the database as ReadWriteCreate (and
failed a Debug.Assert), an undefined Cache was ignored, and an undefined
Synchronous value was sent as PRAGMA synchronous.

Run the string result through the same validation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The enum-validation changes are accompanied by regression coverage for invalid numeric and comma-separated values across the affected options, with no active review issues reported.

No open issues 🎉

What changed in this PR

This pull request fixes inconsistent enum validation in SqliteConnectionStringBuilder by applying Enum.IsDefined to values parsed from strings, preventing undefined numeric and comma-separated enum values from being accepted.

Changes:

  • Validates parsed string enum values before assigning connection options.
  • Adds regression coverage for invalid numeric and comma-separated values across Mode, Cache, and Synchronous.
File Description
test/​Microsoft.Data.Sqlite.Tests/​SqliteConnectionStringBuilderTest.cs Adds regression tests covering invalid numeric and comma-separated string enum values.
src/​Microsoft.Data.Sqlite.Core/​SqliteConnectionStringBuilder.cs Applies defined-value validation to enum values parsed from connection strings.

Review effort: Lite

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution!

@AndriySvyryd AndriySvyryd changed the title Validate enum values parsed from strings in SqliteConnectionStringBuilder Validate enum values parsed from numeric strings in SqliteConnectionStringBuilder Nov 17, 2026
@AndriySvyryd
AndriySvyryd merged commit 5bfb0ba into dotnet:main Nov 17, 2026
20 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants