Skip to content

fix: support typographic quotes and zero-width spaces - #1

Draft
cnbei wants to merge 2 commits into
masterfrom
cursor/unicode-quotes-transactsql-cf53
Draft

fix: support typographic quotes and zero-width spaces#1
cnbei wants to merge 2 commits into
masterfrom
cursor/unicode-quotes-transactsql-cf53

Conversation

@cnbei

@cnbei cnbei commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Fixes sql-formatter-org#942

This PR lives on the fork because the cloud-agent GitHub App token cannot open a pull request on sql-formatter-org/sql-formatter (Resource not accessible by integration).

Open against upstream (intended):
https://github.com/sql-formatter-org/sql-formatter/compare/master...cnbei:sql-formatter:cursor/unicode-quotes-transactsql-cf53?expand=1

gh pr create --repo sql-formatter-org/sql-formatter --head cnbei:cursor/unicode-quotes-transactsql-cf53 --base master

Copy-pasted Transact-SQL from Word/Outlook/web UIs often wraps literals in typographic quotes and inserts zero-width spaces. The playground then throws:

Parse error: Unexpected "'@p0' an" at line 5 column 4.
SQL dialect used: "transactsql".

Cause

The failing token is this 7-character sequence (confirmed from the issue input):

# Char Codepoint Name
1 (invisible) U+200B ZERO WIDTH SPACE
2 U+2018 LEFT SINGLE QUOTATION MARK
3–5 @p0
6 (invisible) U+200B ZERO WIDTH SPACE
7 U+2019 RIGHT SINGLE QUOTATION MARK

Two tokenizer gaps combine to produce the parse error:

  1. WHITESPACE_REGEX is /\s+/uy. JavaScript \s includes NBSP and BOM, but not U+200B, so the lexer does not skip the leading zero-width space.
  2. String rules only match ASCII '. U+2018/U+2019 are not quote delimiters, so tokenization stops with Unexpected "'@p0' an".

Fix

  • Treat U+200B as whitespace, same as the existing Unicode-aware /\s+/u skip.
  • Recognize paired typographic single quotes (‘…’) as a string token, using the same quotePatterns mechanism as ''-qq, [], $$, etc. They are not interchangeable with ASCII ', so a curly apostrophe inside 'don't' still stays inside the string.

The typographic-quote pattern is appended for every dialect in the shared STRING rule: this is a copy-paste artifact, not T-SQL syntax.

Tests

pnpm exec jest --coverage=false: 27 suites, 5907 passed, 1 skipped.
pnpm run ts:check, eslint, and prettier on the changed files are clean.

Open in Web Open in Cursor 

cursoragent and others added 2 commits August 30, 2026 15:47
Tokenize U+2018/U+2019 as string delimiters and treat U+200B as
whitespace so copy-pasted Transact-SQL no longer fails to parse.

Co-authored-by: cnbei <baymy@foxmail.com>
Co-authored-by: cnbei <baymy@foxmail.com>
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.

Problem with unicode quotes in Transact-SQL

2 participants