diff options
author | bptato <nincsnevem662@gmail.com> | 2024-01-08 00:37:54 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-01-08 00:37:54 +0100 |
commit | b0547ba9f48bf402665b89f84b88b80ee58d8824 (patch) | |
tree | 39bf645df6ea365f912040255eb136c5deafe2b1 /adapter | |
parent | 10a02b2ae2613b383453ba99318330560e9371ac (diff) | |
download | chawan-b0547ba9f48bf402665b89f84b88b80ee58d8824.tar.gz |
Add urlenc, urldec; fix a URL encoding bug; improve trans.cgi
* Fix incorrect internal definition of the fragment percent-encode set * urlenc, urldec: these are simple utility programs mainly for use with shell local CGI scripts. (Sadly the printf + xargs solution is not portable.) * Pass libexec directory as an env var to local CGI scripts * Update trans.cgi to use urldec and add an example for combining it with selections
Diffstat (limited to 'adapter')
-rw-r--r-- | adapter/tools/urldec.nim | 6 | ||||
-rw-r--r-- | adapter/tools/urlenc.nim | 41 |
2 files changed, 47 insertions, 0 deletions
diff --git a/adapter/tools/urldec.nim b/adapter/tools/urldec.nim new file mode 100644 index 00000000..b26fcb68 --- /dev/null +++ b/adapter/tools/urldec.nim @@ -0,0 +1,6 @@ +# Percent-decode input received on stdin. +#TODO a streaming implementation of this could be useful + +import utils/twtstr + +stdout.write(percentDecode(stdin.readAll())) diff --git a/adapter/tools/urlenc.nim b/adapter/tools/urlenc.nim new file mode 100644 index 00000000..79d3e452 --- /dev/null +++ b/adapter/tools/urlenc.nim @@ -0,0 +1,41 @@ +# Percent-encode input received on stdin with a specified percent-encoding set. +#TODO a streaming implementation of this could be useful + +import std/os + +import utils/twtstr + +proc usage() = + stderr.write(""" +Usage: urlenc [set] +The input to be decoded is read from stdin. +[set] decides which characters are encoded. It can be: + control + fragment + query + path + userinfo + component + application-x-www-form-urlencoded +""") + +proc main() = + if paramCount() != 1: + usage() + quit(1) + let s = stdin.readAll() + let enc = case paramStr(1) + of "control": percentEncode(s, ControlPercentEncodeSet) + of "fragment": percentEncode(s, FragmentPercentEncodeSet) + of "query": percentEncode(s, QueryPercentEncodeSet) + of "path": percentEncode(s, PathPercentEncodeSet) + of "userinfo": percentEncode(s, UserInfoPercentEncodeSet) + of "component": percentEncode(s, ComponentPercentEncodeSet) + of "application-x-www-form-urlencoded": + percentEncode(s, ApplicationXWWWFormUrlEncodedSet) + else: + usage() + quit(1) + stdout.write(enc) + +main() |