mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
Add Base64 safe (#13672)
* Implement RFC-4648 Section-7 * https://github.com/nim-lang/Nim/pull/13672#issuecomment-600993466
This commit is contained in:
@@ -39,6 +39,21 @@ proc main() =
|
||||
except ValueError:
|
||||
discard
|
||||
|
||||
block base64urlSafe:
|
||||
doAssert encode("c\xf7>", safe = true) == "Y_c-"
|
||||
doAssert encode("c\xf7>", safe = false) == "Y/c+" # Not a nice URL :(
|
||||
doAssert decode("Y/c+") == decode("Y_c-")
|
||||
# Output must not change with safe=true
|
||||
doAssert encode("Hello World", safe = true) == "SGVsbG8gV29ybGQ="
|
||||
doAssert encode("leasure.", safe = true) == "bGVhc3VyZS4="
|
||||
doAssert encode("easure.", safe = true) == "ZWFzdXJlLg=="
|
||||
doAssert encode("asure.", safe = true) == "YXN1cmUu"
|
||||
doAssert encode("sure.", safe = true) == "c3VyZS4="
|
||||
doAssert encode([1,2,3], safe = true) == "AQID"
|
||||
doAssert encode(['h','e','y'], safe = true) == "aGV5"
|
||||
doAssert encode("", safe = true) == ""
|
||||
doAssert encode("the quick brown dog jumps over the lazy fox", safe = true) == "dGhlIHF1aWNrIGJyb3duIGRvZyBqdW1wcyBvdmVyIHRoZSBsYXp5IGZveA=="
|
||||
|
||||
echo "OK"
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user