query
On this page

escapeURL

lib.strings.escapeURL

Docs pulled from | This Revision | about 2 hours 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

Aliases

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);