Skip to content

Unescape doubled single quotes in scaffolded string default values - #39101

Open
ilkertskn wants to merge 1 commit into
dotnet:mainfrom
ilkertskn:fix/scaffold-unescape-string-default-quotes
Open

ilkertskn wants to merge 1 commit into
dotnet:mainfrom
ilkertskn:fix/scaffold-unescape-string-default-quotes

Conversation

@ilkertskn

Copy link
Copy Markdown
Contributor

SqlServerDatabaseModelFactory and SqliteDatabaseModelFactory strip the surrounding quotes from a string literal default (e.g. ('It''s')) but leave the SQL escape sequence '' in place, so the scaffolded model gets HasDefaultValue("It''s"). The migrations SQL generator then escapes the value again and emits DEFAULT N'It''''s', changing the default to It''s.

Replace '' with ' after removing the enclosing quotes in both factories, and add regression tests covering plain, N-prefixed, CONVERT-wrapped and single-quote-only literals.

  • [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

SqlServerDatabaseModelFactory and SqliteDatabaseModelFactory strip the
surrounding quotes from a string literal default (e.g. `('It''s')`) but leave
the SQL escape sequence `''` in place, so the scaffolded model gets
`HasDefaultValue("It''s")`. The migrations SQL generator then escapes the
value again and emits `DEFAULT N'It''''s'`, changing the default to `It''s`.

Replace `''` with `'` after removing the enclosing quotes in both factories,
and add regression tests covering plain, `N`-prefixed, `CONVERT`-wrapped and
single-quote-only literals.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

1 participant