Skip to content

fix: escape special characters in enum values#635

Open
debroys wants to merge 1 commit intoadelsz:masterfrom
debroys:fix/enum-apostrophe-escaping
Open

fix: escape special characters in enum values#635
debroys wants to merge 1 commit intoadelsz:masterfrom
debroys:fix/enum-apostrophe-escaping

Conversation

@debroys
Copy link
Copy Markdown

@debroys debroys commented Dec 31, 2025

Fix for #611

When PostgreSQL enum values contain apostrophes (e.g., car's), pgtyped generates invalid TypeScript:

export type model_enum = 'car's';  // Syntax error

Added escapeEnumValue() function that escapes backslashes and single quotes before wrapping enum values in string literals:

  • car's'car\'s'
  • path\dir'path\\dir'

Added 3 unit tests in packages/cli/src/generator.test.ts covering:

  • Apostrophes in enum values
  • Backslashes in enum values
  • Both characters combined

Fixes adelsz#611 - enum values containing apostrophes or backslashes now
generate valid TypeScript.

Added escapeEnumValue() function that escapes backslashes and single
quotes in enum values before wrapping them in string literals.
@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 31, 2025

Someone is attempting to deploy a commit to the Adel Salakh's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant