Skip to content

fix MATCH query parentheses crash #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions src/forum.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,17 @@ routes:

get "/search.json":
cond "q" in request.params
let q = @"q"
var query = @"q"

var depth = 0
for ch in query:
if ch == '(': depth.inc
elif ch == ')': depth.dec
if depth == 0: discard
elif depth > 0: query.add ')'.repeat(depth)
elif depth < 0: query = '('.repeat(abs(depth)) & query

let q = query
cond q.len > 0

var results: seq[SearchResult] = @[]
Expand All @@ -1618,20 +1628,23 @@ routes:
q, q, $count, $0, q,
q, $count, $0, q
]
for rowFT in fastRows(db, queryFT, data):
var content = rowFT[3]
try: content = content.rstToHtml() except EParseError: discard
results.add(
SearchResult(
kind: SearchResultKind(rowFT[^1].parseInt()),
threadId: rowFT[0].parseInt(),
threadTitle: rowFT[1],
postId: rowFT[2].parseInt(),
postContent: content,
creation: rowFT[4].parseInt(),
author: selectUser(rowFT[5 .. 11]),
try:
for rowFT in fastRows(db, queryFT, data):
var content = rowFT[3]
try: content = content.rstToHtml() except EParseError: discard
results.add(
SearchResult(
kind: SearchResultKind(rowFT[^1].parseInt()),
threadId: rowFT[0].parseInt(),
threadTitle: rowFT[1],
postId: rowFT[2].parseInt(),
postContent: content,
creation: rowFT[4].parseInt(),
author: selectUser(rowFT[5 .. 11]),
)
)
)
except DbError:
discard
Comment on lines +1646 to +1647
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will just return empty results. Which isn't much better than an error.


resp Http200, $(%results), "application/json"

Expand Down