escapeURL
lib.strings.escapeURL
Docs pulled from | This Revision | 43 minutes ago
Escape the string
so it can be safely placed inside a URL
query.
Inputs
string
- 1. Function argument
Type
escapeURL :: string -> string
Examples
lib.strings.escapeURL
usage example
escapeURL "foo/bar baz"
=> "foo%2Fbar%20baz"
Noogle detected
Implementation
This function is implemented in c++ and is part of the native nix runtime.
Implementation
The following is the current implementation of this function.
escapeURL = let
unreserved = [ "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "-" "_" "." "~" ];
toEscape = builtins.removeAttrs asciiTable unreserved;
in
replaceStrings (builtins.attrNames toEscape) (lib.mapAttrsToList (_: c: "%${fixedWidthString 2 "0" (lib.toHexString c)}") toEscape);