fix(export): don't treat a plain-text default ending in (…) as a function - #1125
Open
NgoQuocViet2001 wants to merge 1 commit into
Open
fix(export): don't treat a plain-text default ending in (…) as a function#1125NgoQuocViet2001 wants to merge 1 commit into
NgoQuocViet2001 wants to merge 1 commit into
Conversation
…tion
isFunction was anchored only at the end:
/\w+\([^)]*\)$/
so any default that merely finishes with a parenthesised word matched.
parseDefault consults it before the quoting branch, so those defaults
were written into the exported SQL unquoted:
Call now(free) -> DEFAULT Call now(free) -- invalid
see item(s) -> DEFAULT see item(s) -- invalid
Anchor the pattern at the start as well. The dot in the character class
keeps qualified names such as pg_catalog.now() matching, and the
non-string guard mirrors isKeyword directly above.
|
@NgoQuocViet2001 is attempting to deploy a commit to the dottle's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
A column default that is ordinary text but happens to end in a parenthesised word is exported as if it were a SQL function call — unquoted — which produces invalid SQL.
Why
isFunctionis anchored only at the end:parseDefaultconsults it before the quoting branch, so anything it accepts is emitted verbatim:Nothing upstream constrains the value — the Default box in
FieldDetails.jsxis free text.Anchoring at the start fixes it. The
.in the class keeps qualified names likepg_catalog.now()matching, and the non-string guard mirrorsisKeywordimmediately above it.Verified
Through the real
parseDefault:And on
isFunctiondirectly, over a battery of real function defaults and plain-text lookalikes — 2 fixed, 0 regressions:now()gen_random_uuid()CURRENT_TIMESTAMP()nextval('s')pg_catalog.now()Call now(free)see item(s)Item (s)now ()hello worldDeliberately not fixed
A default that is itself shaped like a call —
a(b),text_(1)— is still treated as a function. That ambiguity is inherent to guessing from a free-text field and can only be settled by asking the user which they meant, so it is out of scope here.I also tried allowing whitespace before the paren (
now ()), but it makesItem (s)match, which is worse than the case it fixes.now ()was alreadyfalsebefore this change, so leaving it is not a regression.Checks
npm run lint— clean (--max-warnings 0).npm run build— succeeds.The repo has no test suite, so the tables above come from scratch scripts run against the real modules; they are not part of the diff.