fix doc search(escape HTML code) (#15433)

* use release version

* fix doc search
This commit is contained in:
flywind
2020-09-30 16:52:49 +08:00
committed by GitHub
parent eb2a4961c7
commit 9c86f4867e

View File

@@ -267,6 +267,19 @@ var
template normalize(x: cstring): cstring = x.toLower.replace("_", "")
proc escapeCString(x: var cstring) =
var s = ""
for c in x:
case c
of '&': s.add("&")
of '<': s.add("&lt;")
of '>': s.add("&gt;")
of '"': s.add("&quot;")
of '\'': s.add("&#039;")
of '/': s.add("&#x2F;")
else: s.add(c)
x = s.cstring
proc dosearch(value: cstring): Element =
if db.len == 0:
var stuff: Element
@@ -305,6 +318,7 @@ proc dosearch(value: cstring): Element =
matches.sort(proc(a, b: auto): int = b[1] - a[1])
for i in 0 ..< min(matches.len, 29):
matches[i][0].innerHTML = matches[i][0].getAttribute("data-doc-search-tag")
escapeCString(matches[i][0].innerHTML)
ul.add(tree("LI", cast[Element](matches[i][0])))
if ul.len == 0:
result.add tree("B", text"no search results")