mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 10:10:28 +00:00
fix: fixing parsing with SELECT keywords outside sql queries
This commit is contained in:
parent
a2021a98eb
commit
0df95981a2
2 changed files with 58 additions and 1 deletions
|
|
@ -450,4 +450,61 @@ SELECT id, value FROM data`, DEFAULT_VIEWS, DEFAULTS)).toEqual({
|
|||
}]
|
||||
})
|
||||
})
|
||||
|
||||
it('should not treat "select" as SQL keyword when it appears as a quoted config property key', () => {
|
||||
// Test case for fix: quoted string "select" as a property key should not break the parser
|
||||
expect(parseWithDefaults(`
|
||||
GRID {
|
||||
"select": 4
|
||||
}
|
||||
SELECT * FROM files`, DEFAULT_VIEWS, DEFAULTS)).toEqual({
|
||||
flags: { explain: false, refresh: true },
|
||||
query: 'SELECT * FROM files',
|
||||
renderer: {
|
||||
type: 'GRID',
|
||||
options: `{
|
||||
"select": 4
|
||||
}`,
|
||||
},
|
||||
tables: []
|
||||
})
|
||||
})
|
||||
|
||||
it('should not treat "select" as SQL keyword when it appears as an unquoted config property key', () => {
|
||||
// Bonus test: unquoted property key with colon immediately following
|
||||
expect(parseWithDefaults(`
|
||||
GRID {
|
||||
select: 4
|
||||
}
|
||||
SELECT * FROM files`, DEFAULT_VIEWS, DEFAULTS)).toEqual({
|
||||
flags: { explain: false, refresh: true },
|
||||
query: 'SELECT * FROM files',
|
||||
renderer: {
|
||||
type: 'GRID',
|
||||
options: `{
|
||||
select: 4
|
||||
}`,
|
||||
},
|
||||
tables: []
|
||||
})
|
||||
})
|
||||
|
||||
it('should handle "select" as property key with space before colon', () => {
|
||||
// Edge case: space between quoted key and colon
|
||||
expect(parseWithDefaults(`
|
||||
GRID {
|
||||
"select" : 4
|
||||
}
|
||||
SELECT * FROM files`, DEFAULT_VIEWS, DEFAULTS)).toEqual({
|
||||
flags: { explain: false, refresh: true },
|
||||
query: 'SELECT * FROM files',
|
||||
renderer: {
|
||||
type: 'GRID',
|
||||
options: `{
|
||||
"select" : 4
|
||||
}`,
|
||||
},
|
||||
tables: []
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -53,7 +53,7 @@ export const SQLSealLangDefinition = (views: ViewDefinition[], flags: readonly F
|
|||
anyObject = "{" (~selectKeyword any)*
|
||||
handlebarsTemplate = (~selectKeyword any)*
|
||||
javascriptTemplate = (~selectKeyword any)*
|
||||
selectKeyword = (caseInsensitive<"WITH"> | caseInsensitive<"SELECT">) ~(alnum | "_")
|
||||
selectKeyword = (caseInsensitive<"WITH"> | caseInsensitive<"SELECT">) &(space | nl | end)
|
||||
tableKeyword = caseInsensitive<"TABLE">
|
||||
nl = "\n"
|
||||
character = (alnum | "." | "-" | space | "_")
|
||||
|
|
|
|||
Loading…
Reference in a new issue