Skip to content

Commit 2c451db

Browse files
committed
new brackets crash fix version
1 parent d20553c commit 2c451db

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/forum.nim

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,8 +1607,17 @@ routes:
16071607

16081608
get "/search.json":
16091609
cond "q" in request.params
1610-
let forbiddenSymbols = @[("(", ""), (")", "")]
1611-
let q = @"q".multiReplace(forbiddenSymbols)
1610+
var query = @"q"
1611+
1612+
var depth = 0
1613+
for ch in query:
1614+
if ch == '(': depth.inc
1615+
if ch == ')': depth.dec
1616+
if depth == 0: discard
1617+
elif depth > 0: query.add ')'.repeat(depth)
1618+
elif depth < 0: query = '('.repeat(abs(depth)) & query
1619+
1620+
let q = query
16121621
cond q.len > 0
16131622

16141623
var results: seq[SearchResult] = @[]
@@ -1619,20 +1628,23 @@ routes:
16191628
q, q, $count, $0, q,
16201629
q, $count, $0, q
16211630
]
1622-
for rowFT in fastRows(db, queryFT, data):
1623-
var content = rowFT[3]
1624-
try: content = content.rstToHtml() except EParseError: discard
1625-
results.add(
1626-
SearchResult(
1627-
kind: SearchResultKind(rowFT[^1].parseInt()),
1628-
threadId: rowFT[0].parseInt(),
1629-
threadTitle: rowFT[1],
1630-
postId: rowFT[2].parseInt(),
1631-
postContent: content,
1632-
creation: rowFT[4].parseInt(),
1633-
author: selectUser(rowFT[5 .. 11]),
1631+
try:
1632+
for rowFT in fastRows(db, queryFT, data):
1633+
var content = rowFT[3]
1634+
try: content = content.rstToHtml() except EParseError: discard
1635+
results.add(
1636+
SearchResult(
1637+
kind: SearchResultKind(rowFT[^1].parseInt()),
1638+
threadId: rowFT[0].parseInt(),
1639+
threadTitle: rowFT[1],
1640+
postId: rowFT[2].parseInt(),
1641+
postContent: content,
1642+
creation: rowFT[4].parseInt(),
1643+
author: selectUser(rowFT[5 .. 11]),
1644+
)
16341645
)
1635-
)
1646+
except DbError:
1647+
discard
16361648

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

0 commit comments

Comments
 (0)