diff options
author | flywind <43030857+xflywind@users.noreply.github.com> | 2020-09-30 16:52:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-30 10:52:49 +0200 |
commit | 9c86f4867e8475e38e1e8fb026b9cfd1555271a8 (patch) | |
tree | 447e08a178be4650b060e6dac7130887e155f4bf /tools/dochack | |
parent | eb2a4961c71029c874ebdacd1b23a349eb8e61d5 (diff) | |
download | Nim-9c86f4867e8475e38e1e8fb026b9cfd1555271a8.tar.gz |
fix doc search(escape HTML code) (#15433)
* use release version * fix doc search
Diffstat (limited to 'tools/dochack')
-rw-r--r-- | tools/dochack/dochack.nim | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/dochack/dochack.nim b/tools/dochack/dochack.nim index 4c4db4638..471212a50 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") |