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 /src/utils/twtstr.nim | |
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 'src/utils/twtstr.nim')
-rw-r--r-- | src/utils/twtstr.nim | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index d7e5a5ba..f1af1998 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -491,19 +491,25 @@ func isNonCharacter*(r: Rune): bool = 0xCFFFE, 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, 0x10FFFF] -const ControlPercentEncodeSet* = (Controls + NonAscii) -const FragmentPercentEncodeSet* = (Controls + NonAscii) -const QueryPercentEncodeSet* = (ControlPercentEncodeSet + {' ', '"', '#', '<', '>'}) -const SpecialQueryPercentEncodeSet* = (QueryPercentEncodeSet + {'\''}) -const PathPercentEncodeSet* = (QueryPercentEncodeSet + {'?', '`', '{', '}'}) -const UserInfoPercentEncodeSet* = (PathPercentEncodeSet + {'/', ':', ';', '=', '@', '['..'^', '|'}) -const ComponentPercentEncodeSet* = (UserInfoPercentEncodeSet + {'$'..'&', '+', ','}) -const ApplicationXWWWFormUrlEncodedSet* = (ComponentPercentEncodeSet + {'!', '\''..')', '~'}) -# used by client -when defined(windows) or defined(OS2) or defined(DOS): - const LocalPathPercentEncodeSet* = (Ascii - AsciiAlpha - AsciiDigit - {'.', '\\', '/'}) +const ControlPercentEncodeSet* = Controls + NonAscii +const FragmentPercentEncodeSet* = ControlPercentEncodeSet + + {' ', '"', '<', '>', '`'} +const QueryPercentEncodeSet* = FragmentPercentEncodeSet - {'`'} + {'#'} +const SpecialQueryPercentEncodeSet* = QueryPercentEncodeSet + {'\''} +const PathPercentEncodeSet* = QueryPercentEncodeSet + {'?', '`', '{', '}'} +const UserInfoPercentEncodeSet* = PathPercentEncodeSet + + {'/', ':', ';', '=', '@', '['..'^', '|'} +const ComponentPercentEncodeSet* = UserInfoPercentEncodeSet + + {'$'..'&', '+', ','} +const ApplicationXWWWFormUrlEncodedSet* = ComponentPercentEncodeSet + + {'!', '\''..')', '~'} +# used by pager +when DirSep == '\\': + const LocalPathPercentEncodeSet* = Ascii - AsciiAlpha - AsciiDigit - + {'.', '\\', '/'} else: - const LocalPathPercentEncodeSet* = (Ascii - AsciiAlpha - AsciiDigit - {'.', '/'}) + const LocalPathPercentEncodeSet* = Ascii - AsciiAlpha - AsciiDigit - + {'.', '/'} proc percentEncode*(append: var string, c: char, set: set[char], spaceAsPlus = false) {.inline.} = if spaceAsPlus and c == ' ': |