(backported) fixed fields extraction for view queries with milti-level comments

This commit is contained in:
Gani Georgiev committed 2025-01-18 12:23:41 +02:00
1 parent fbb8fca48e
commit ae36612c34
3 files changed
+22 -7

No files matched your search

+5
View File
@@ -1,3 +1,8 @@
## v0.22.30
- (_Backported from v0.24.4_) Fixed fields extraction for view queries with milti-level comments ([#6309](https://github.com/pocketbase/pocketbase/discussions/6309)).
## v0.22.29 ## v0.22.29
- (_Backported from v0.23.11_) Upgraded `golang.org/x/net` to 0.33.0 to fix [CVE-2024-45338](https://www.cve.org/CVERecord?id=CVE-2024-45338). - (_Backported from v0.23.11_) Upgraded `golang.org/x/net` to 0.33.0 to fix [CVE-2024-45338](https://www.cve.org/CVERecord?id=CVE-2024-45338).
+4 -4
View File
@@ -462,9 +462,9 @@ type identifiersParser struct {
func (p *identifiersParser) parse(selectQuery string) error { func (p *identifiersParser) parse(selectQuery string) error {
str := strings.Trim(strings.TrimSpace(selectQuery), ";") str := strings.Trim(strings.TrimSpace(selectQuery), ";")
str = joinReplaceRegex.ReplaceAllString(str, " _join_ ")
str = discardReplaceRegex.ReplaceAllString(str, " _discard_ ")
str = commentsReplaceRegex.ReplaceAllString(str, "") str = commentsReplaceRegex.ReplaceAllString(str, "")
str = joinReplaceRegex.ReplaceAllString(str, " __pb_join__ ")
str = discardReplaceRegex.ReplaceAllString(str, " __pb_discard__ ")
tk := tokenizer.NewFromString(str) tk := tokenizer.NewFromString(str)
tk.Separators(',', ' ', '\n', '\t') tk.Separators(',', ' ', '\n', '\t')
@@ -499,7 +499,7 @@ func (p *identifiersParser) parse(selectQuery string) error {
skip = false skip = false
partType = "from" partType = "from"
activeBuilder = &fromParts activeBuilder = &fromParts
case "_join_": case "__pb_join__":
skip = false skip = false
// the previous part was also a join // the previous part was also a join
@@ -509,7 +509,7 @@ func (p *identifiersParser) parse(selectQuery string) error {
partType = "join" partType = "join"
activeBuilder = &joinParts activeBuilder = &joinParts
case "_discard_": case "__pb_discard__":
// skip following tokens // skip following tokens
skip = true skip = true
default: default:
+13 -3
View File
@@ -248,11 +248,21 @@ func TestCreateViewSchema(t *testing.T) {
` `
select select
-- test single line -- test single line
id, demo1.id,
text, demo1.text,
/* multi /* multi
line comment */ line comment */
url, created, updated from demo1 demo1.url, demo1.created, demo2.updated from demo1
-- comment before join
join demo2 ON (
-- comment inside join
demo2.id = demo1.id
)
-- comment before where
where (
-- comment inside where
demo2.id = demo1.id
)
`, `,
false, false,
map[string]string{ map[string]string{