diff options
author | Araq <rumpf_a@web.de> | 2014-09-10 23:25:29 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-09-10 23:25:29 +0200 |
commit | 950078003767de36132f179ca00d8c81dbcc162a (patch) | |
tree | 8b183c05621213d64978eb1ed87d44b660db71f7 /lib/pure | |
parent | 758d8e11d9a4aa1d15572c246e63ed5ea913aad9 (diff) | |
download | Nim-950078003767de36132f179ca00d8c81dbcc162a.tar.gz |
renamed URLencode to encodeUrl
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/cgi.nim | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/pure/cgi.nim b/lib/pure/cgi.nim index d5690bf51..e8977b80b 100644 --- a/lib/pure/cgi.nim +++ b/lib/pure/cgi.nim @@ -31,7 +31,7 @@ import strutils, os, strtabs, cookies -proc urlEncode*(s: string): string = +proc encodeUrl*(s: string): string = ## Encodes a value to be HTTP safe: This means that characters in the set ## ``{'A'..'Z', 'a'..'z', '0'..'9', '_'}`` are carried over to the result, ## a space is converted to ``'+'`` and every other character is encoded as @@ -52,7 +52,7 @@ proc handleHexChar(c: char, x: var int) {.inline.} = of 'A'..'F': x = (x shl 4) or (ord(c) - ord('A') + 10) else: assert(false) -proc urlDecode*(s: string): string = +proc decodeUrl*(s: string): string = ## Decodes a value from its HTTP representation: This means that a ``'+'`` ## is converted to a space, ``'%xx'`` (where ``xx`` denotes a hexadecimal ## value) is converted to the character with ordinal number ``xx``, and @@ -74,6 +74,8 @@ proc urlDecode*(s: string): string = inc(j) setLen(result, j) +{.deprecated: [URLDecode: decodeUrl, URLEncode: encodeUrl].} + proc addXmlChar(dest: var string, c: char) {.inline.} = case c of '&': add(dest, "&") @@ -100,7 +102,7 @@ type methodGet ## query uses the GET method {.deprecated: [TRequestMethod: RequestMethod, ECgi: CgiError, - URLencode: urlEncode, XMLencode: xmlEncode, URLdecode: urlDecode].} + XMLencode: xmlEncode].} proc cgiError*(msg: string) {.noreturn.} = ## raises an ECgi exception with message `msg`. @@ -332,9 +334,9 @@ proc setTestData*(keysvalues: varargs[string]) = var i = 0 var query = "" while i < keysvalues.len: - add(query, urlEncode(keysvalues[i])) + add(query, encodeUrl(keysvalues[i])) add(query, '=') - add(query, urlEncode(keysvalues[i+1])) + add(query, encodeUrl(keysvalues[i+1])) add(query, '&') inc(i, 2) putEnv("QUERY_STRING", query) @@ -394,5 +396,5 @@ proc existsCookie*(name: string): bool = when isMainModule: const test1 = "abc\L+def xyz" - assert URLencode(test1) == "abc%0A%2Bdef+xyz" - assert URLdecode(URLencode(test1)) == test1 + assert encodeUrl(test1) == "abc%0A%2Bdef+xyz" + assert decodeUrl(encodeUrl(test1)) == test1 |