UrlEncode - ObjectVision/GeoDMS GitHub Wiki
String functions UrlEncode
The UrlEncode function encodes strings for safe use in URLs by escaping special characters.
UrlEncode(strings: E->String) -> E->String
Converts strings to URL-safe format: a space becomes +, and every other byte outside the unreserved set becomes a percent-encoded %XX sequence with UPPERCASE hex digits (& becomes %26, < becomes %3C).
UrlEncode is the exact inverse of UrlDecode: UrlDecode(UrlEncode(x)) returns x for every string, non-ASCII content included.
Characters that remain unencoded - the unreserved set of RFC2396:
- Letters (A-Z, a-z) and digits (0-9)
- The mark characters
-,_,.,!,~,*,',(,)
Everything else is encoded, in particular:
- A space becomes
+(not%20), which is what UrlDecode reads back as a space - A literal
+becomes%2B, for that same reason - Control characters and the reserved URL characters
#,$,&,,,/,:,;,=,?,@,[,] - Every non-ASCII byte, as one
%XXper byte; UTF-8 text is therefore encoded as its UTF-8 byte sequence
| argument | description | type |
|---|---|---|
| strings | Input strings to encode | E->String |
Time complexity: O(n × L) where n is the number of strings and L is the average string length.
Encoded strings are typically longer than input strings (each special character becomes 3 characters).
unit<uint32> QueryParams: nrofrows = 3;
attribute<String> values (QueryParams) := union_data(QueryParams,
'hello world',
'price=100&tax=20',
'name=Müller'
);
attribute<String> encoded (QueryParams) := UrlEncode(values);
// encoded = {'hello+world', 'price%3D100%26tax%3D20', 'name%3DM%C3%BCller'}
// Building URL query string
parameter<String> base_url := 'https://api.example.com/search?q=';
attribute<String> full_url (QueryParams) := base_url + encoded;
- UrlDecode - reverse operation
- HtmlEncode - for HTML content
- String functions
20.13.0