fix(pgsql): Escape Cypher Characters in Literals - BED-7883#71
fix(pgsql): Escape Cypher Characters in Literals - BED-7883#71LawsonWillard merged 4 commits intomainfrom
Conversation
|
Caution Review failedFailed to post review comments WalkthroughThe PR adds escaping for Cypher single-quoted string literals via ChangesString Literal Escaping and Decoding
Sequence DiagramsequenceDiagram
participant User
participant CypherModel as Cypher Model
participant Formatter as Cypher Formatter
participant Translator as PostgreSQL Translator
participant PG as PostgreSQL Literal
User->>CypherModel: provide raw string
CypherModel->>CypherModel: escape backslashes and single quotes
CypherModel-->>User: return Cypher `Literal` (escaped)
User->>Formatter: include Literal in query
Formatter->>Formatter: render Literal with quotes
Formatter-->>User: emit Cypher query string
User->>Translator: pass Cypher literal value
Translator->>Translator: decode escape sequences and strip quotes
Translator-->>PG: produce decoded Postgres literal
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cypher/models/pgsql/translate/translator.go`:
- Around line 479-500: The decodeCypherStringLiteral function currently rejects
\u and \U Unicode escapes; update the escape handling in translator.go (inside
decodeCypherStringLiteral switch) to support '\u' followed by exactly 4 hex
digits and '\U' followed by exactly 8 hex digits: validate there are enough
bytes remaining, parse the hex digits, return an error on non-hex digits or
incomplete sequences, validate the resulting code point is a legal Unicode
scalar (<= 0x10FFFF and not a surrogate 0xD800–0xDFFF), and append the
corresponding UTF-8 encoding to the output buffer; keep existing error behavior
for other invalid escapes and update tests that previously expected failure for
\u/\U.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0a0681da-6b00-4182-93b8-3dd9d31aae5e
📒 Files selected for processing (4)
cypher/models/cypher/format/format_test.gocypher/models/cypher/model.gocypher/models/pgsql/translate/translator.gocypher/models/pgsql/translate/translator_test.go
|
We should really consider auto-parameterization of literals. Escaping is often a game of edge cases and pushing these into parameters such that |
Completely agree! Took a quick look into what it would take to implement this and seems like the majority of the work will be in ensuring tests are updated and working as expected. Its been a bit since I was in DAWGS and don't want to hold up the corresponding bug ticket as I implement this. Ticket I just created is a duplicate of https://specterops.atlassian.net/browse/BED-8047 |
Description
Resolves: BED-7883
Type of Change
Testing
Added new unit tests
go test -tags manual_integration ./integration/...)Screenshots (if appropriate):
Driver Impact
drivers/pg)drivers/neo4j)Checklist
go.mod/go.sumare up to date if dependencies changedSummary by CodeRabbit
Bug Fixes
Tests