assert(percentDecode("IDontNeedNoPercentDecoding") == "IDontNeedNoPercentDecoding"); assert(percentDecode("~~--..__") == "~~--..__"); assert(percentDecode("0123456789") == "0123456789"); string e; e = percentDecode("%E2%98%83"); assert(e == "☃", "expected a snowman but got" ~ e); e = percentDecode("%e2%98%83"); assert(e == "☃", "expected a snowman but got" ~ e); try { // %ES is an invalid percent sequence: 'S' is not a hex digit. percentDecode("%es"); assert(false, "expected exception not thrown"); } catch (URLException) { } try { percentDecode("%e"); assert(false, "expected exception not thrown"); } catch (URLException) { }
Percent-decode a string.
URL components cannot contain non-ASCII characters, and there are very few characters that are safe to include as URL components. Domain names using Unicode values use Punycode. For everything else, there is percent encoding.
This explicitly ensures that the result is a valid UTF-8 string.