Skip to content

Commit 1be4576

Browse files
authored
fixes #362; escapes search results (#363)
* fixes #362; escapes search results * fixes comments
1 parent 4fecb59 commit 1be4576

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/forum.nim

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import
1010
os, strutils, times, md5, strtabs, math,
1111
jester, asyncdispatch, asyncnet, sequtils,
1212
parseutils, random, rst, recaptcha, json, re, sugar,
13-
strformat, logging
13+
strformat, logging, xmltree
1414
import cgi except setCookie
1515
import std/options
1616

@@ -1634,15 +1634,19 @@ routes:
16341634
q, $count, $0, q
16351635
]
16361636
for rowFT in fastRows(db, queryFT, data):
1637-
var content = rowFT[3]
1638-
try: content = content.rstToHtml() except EParseError: discard
1637+
let content = rowFT[3]
1638+
var outcome = ""
1639+
try: outcome = content.rstToHtml()
1640+
except EParseError:
1641+
warn("Could not parse rst html.")
1642+
outcome = xmltree.escape(content) # bug #362 escapes content
16391643
results.add(
16401644
SearchResult(
16411645
kind: SearchResultKind(rowFT[^1].parseInt()),
16421646
threadId: rowFT[0].parseInt(),
16431647
threadTitle: rowFT[1],
16441648
postId: rowFT[2].parseInt(),
1645-
postContent: content,
1649+
postContent: outcome,
16461650
creation: rowFT[4].parseInt(),
16471651
author: selectUser(rowFT[5 .. 11]),
16481652
)

src/utils.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import asyncdispatch, smtp, strutils, json, os, rst, rstgen, xmltree, strtabs,
1+
import asyncdispatch, smtp, strutils, json, os, xmltree, strtabs,
22
htmlparser, streams, parseutils, options, logging
33
from times import getTime, utc, format
44

5+
import packages/docutils/[rst, rstgen]
6+
57
# Used to be:
68
# {'A'..'Z', 'a'..'z', '0'..'9', '_', '\128'..'\255'}
79
let

0 commit comments

Comments
 (0)