Repository navigation
fix: keep brackets around keyword column names in toString() - #3074
Open
abhi478jeetur-rgb wants to merge 3 commits into
Open
abhi478jeetur-rgb wants to merge 3 commits into
abhi478jeetur-rgb wants to merge 3 commits into
Conversation
Column.needsBrackets only checked for spaces, dots, dashes and brackets, so toString() printed a keyword column name like [value] or [select] bare. The printed SQL then parsed as something else ([value]->a lost its result) or did not parse at all (SELECT [select]->a). Also bracket a name the lexer reads as a keyword: ask the parser's own lexer whether the name tokenizes as LITERAL, and cache the answer per name. Non-keyword names (id, user, ...) still print bare. Fixes AlaSQL#3073
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.
What this PR does
Column.needsBracketsonly checked for spaces, dots, dashes and brackets, sotoString()printed a column name that is a keyword — e.g.[value]or[select]— without brackets. The printed SQL then parsed as something else ([value]->alost its result:[{id:1}]instead of[{id:1,x:5}]) or did not parse at all (SELECT [select]->a AS x FROM ?).needsBracketsnow also brackets a name the lexer reads as a keyword: it asks the parser's own lexer whether the name tokenizes as a plain identifier (LITERAL) and caches the answer per name, so the check always agrees with the grammar and needs no separate keyword list. Non-keyword names (id,user, ...) still print bare.Tests
New
test/test3073.js(5 tests) — each case parses, prints withtoString(), parses again and compares the results, covering keyword column names in the select list, in->, in WHERE and in ORDER BY, as suggested in the issue. The issue's two examples are reproduced verbatim. Before the fix 4 of the 5 tests failed; after the fix all 5 pass.Full test suite (
sh build.sh && bun test): 2638 passed, 213 skipped, 0 failed (2851 tests, 693 files). Prettier check clean.Fixes #3073