Repository navigation
fix(plpgsql-deparser): keep multi-line literals, "char" and empty CASE ELSE intact - #365
pyramation wants to merge 1 commit into
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
This PR fixes three PL/pgSQL deparser round-trip bugs, each backed by a new fixture in
Reviewed commit: ffd037e |
There was a problem hiding this comment.
Adds three PL/pgSQL fixtures (multi-line literals, quoted "char", empty ELSE) and teaches the deparser to preserve literal newlines when indenting, keep "char" quoted, and deparse an empty ELSE branch.
Key findings
- 🟡 Quote-stripping still mangles other quoted type names — plpgsql-deparser.ts:886
| // Simple type - strip quotes unless they change the meaning ("char" is not char) | ||
| const trimmed = typname.trim(); | ||
| return /^"char"(\[\d*\])*$/.test(trimmed) ? trimmed : trimmed.replace(/"/g, ''); | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Quote-stripping still mangles other quoted type names
The new guard protects only the exact name "char" (plus array suffixes); every other quoted simple type is still blindly unquoted at packages/plpgsql-deparser/src/plpgsql-deparser.ts:888. A quoted mixed-case or otherwise unquotable type name such as "CHAR" or "my type" is emitted as CHAR / my type, silently re-resolving to the built-in char or producing invalid SQL. This is the same meaning-changing-unquoting defect the change fixes for "char", left unhandled for all other quoted names.
📋 Prompt for AI Agents
In packages/plpgsql-deparser/src/plpgsql-deparser.ts around lines 886-889, replace the blanket trimmed.replace(/"/g, '') with a conditional: keep the quotes unless the inner content is already a valid lowercase unquoted identifier (/^[a-z_][a-z0-9_$]*$/), with the documented exception that "char" is always preserved as-is per the existing regex. This prevents quoted names like "CHAR" or "my type" from being silently unquoted into a different or invalid type.
|
Folded into #371 |
Summary
Three PL/pgSQL deparser bugs that changed what a function does after a parse → deparse round trip:
RAISE NOTICE 'ab';inside anIF'ab'indent()added indentation after every newline, including the ones inside string literals and dollar quotes. Message text andEXECUTE format(...)SQL changed.DECLARE c "char";c char;"char"(1-byte internal type) is notchar(bpchar(1)).CASE x WHEN 1 THEN ... ELSE END CASE;ELSEdroppedELSEwas emitted only whenelse_stmtswas non-empty. Without it, a non-matching value raisesCASE_NOT_FOUND.Fixes:
indent()now scans the text and indents only newlines outside'...'(withE'...'backslash escapes),"...", and$tag$...$tag$. Newlines in comments are still indented.skipQuoted()is the new helper.deparseType()keeps the quotes on"char"(and"char"[]). All other simple types behave as before.CASEemitsELSEwheneverhave_elseis set.Tests
Added fixtures 68–70 to
__fixtures__/plpgsql/plpgsql_deparser_fixes.sqland regeneratedplpgsql-generated/generated.jsonwithnpm run fixtures.AST_MISMATCH: plpgsql_deparser_fixes-68.sql/-69.sql/-70.sqlAll three bugs also exist in plpgsql-deparser 18.3.0, so they are not regressions in 18.3.1.
Link to Devin session: https://app.devin.ai/sessions/f8a1d342fa3b4580a90de9031ed4bd86
Open in Devin Desktop: https://app.devin.ai/desktop/session/f8a1d342fa3b4580a90de9031ed4bd86?variant=devin
Requested by: @pyramation