about summary refs log tree commit diff stats
path: root/src/utils
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-19 16:45:09 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-19 16:55:22 +0200
commit415ad6988dabb1535dd0bfe9532c4395df8688e2 (patch)
tree23f25642b618f598275fc59b2301a93a13095815 /src/utils
parente8da184531c774a6388576dab3dbe4182eab9473 (diff)
downloadchawan-415ad6988dabb1535dd0bfe9532c4395df8688e2.tar.gz
ftp: encode paths, escape displayed strings
avoid e.g. # being interpreted as a fragment
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/twtstr.nim17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 7589c262..64f66f88 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -546,6 +546,23 @@ func percentDecode*(input: string, si = 0): string =
         i += 2
     inc i
 
+func htmlEscape*(s: string): string =
+  var res = ""
+  for c in s:
+    if c == '<':
+      res &= "&lt;"
+    elif c == '>':
+      res &= "&gt;"
+    elif c == '&':
+      res &= "&amp;"
+    elif c == '"':
+      res &= "&quot;"
+    elif c == '\'':
+      res &= "&apos;"
+    else:
+      res &= c
+  return res
+
 #basically std join but with char
 func join*(ss: openarray[string], sep: char): string =
   if ss.len == 0: