Skip to content

fix: add SQL-standard '' single quote escape in Cypher string literals#729

Open
chiangchenghsin-hash wants to merge 1 commit into
LadybugDB:mainfrom
chiangchenghsin-hash:fix/cypher-sql-quote-escape
Open

fix: add SQL-standard '' single quote escape in Cypher string literals#729
chiangchenghsin-hash wants to merge 1 commit into
LadybugDB:mainfrom
chiangchenghsin-hash:fix/cypher-sql-quote-escape

Conversation

@chiangchenghsin-hash

Copy link
Copy Markdown
Contributor

Summary

Adds SQL-92 standard two-single-quotes ('') escape support within Cypher single-quoted string literals, complementing the existing backslash (\') escape.

Problem

Cypher uses backslash escapes for strings ('It\'s a test'), which differs from the SQL standard ('It''s a test'). This causes parser exceptions when users write SQL-style escaped strings — a common pitfall for those coming from SQL backgrounds.

Fix

Two changes:

  1. src/parser/transformer.cpp: In transformStringLiteral(), add handling for consecutive single quotes ('') before the fallback else branch — translates '' to '.

  2. src/antlr4/Cypher.g4: Add '\'\'' as an alternative within the single-quoted StringLiteral rule, so the ANTLR lexer recognizes '' as a valid token sequence inside a string literal.

Verification

  • Windows 11 x64, LadybugDB 0.18.3
  • "It's working" (double-quote workaround for single quotes) — ✅ already works
  • 'It''s a test' (SQL-style escape) — ✅ fixed (was Parser exception before)

Support the SQL-92 standard two-single-quotes escape sequence ('')
within Cypher string literals, complementing the existing backslash
escape. Fixes parser failures on strings like 'It''s a test'.

Changes:
- transformer.cpp: handle '' → ' in transformStringLiteral()
- Cypher.g4: add '\\'\\'' alternative to StringLiteral grammar rule
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