From 9c86f4867e8475e38e1e8fb026b9cfd1555271a8 Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Wed, 30 Sep 2020 16:52:49 +0800 Subject: [PATCH] fix doc search(escape HTML code) (#15433) * use release version * fix doc search --- tools/dochack/dochack.nim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/dochack/dochack.nim b/tools/dochack/dochack.nim index 4c4db46383..471212a504 100644 --- a/tools/dochack/dochack.nim +++ b/tools/dochack/dochack.nim @@ -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("<") + of '>': s.add(">") + of '"': s.add(""") + of '\'': s.add("'") + of '/': s.add("/") + 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")