Erlang URL encoding

  • URL encoding method description

Reference

RFC 1738

  • Replace all non-alphanumeric characters in the string except “-_.” with a percent sign (%) followed by two hexadecimal digits

rfc1738

RFC 3986

  • RFC-3986 adopts a unified encoding method. The encoding format of characters is: %HH (H is a hexadecimal character). No special treatment is done for spaces. According to the RFC-3986 specification, spaces are encoded as %20, and plus signs “+” are encoded as %2B.

rfc3986

RFC 2396

  • RFC 3986 is an upgraded version

HTML4.01

  • ContextType=x-www-form-urlencoded
  • Spaces are escaped as +
  • Other characters are handled by the RFC 1738 standard

Erlang processing

cow_qs.erl

cow_qs:urldecode/1
cow_qs:urlencode/1
cow_qs:urlencode(<<"a b+c">>).
<<"a+b%2Bc">>

cow_uri.erl

cow_uri:urldecode/1
cow_uri:urlencode/1
cow_uri:urlencode(<<"a b+c">>).
<<"a%20b+c">>

Usage

  • Use cow_qs:urlencode/1 for connecting to external systems
  • uri_string.erl module added after OTP 21.0

Implement RFC 3986 and HTML 5.2

uri_string:compose_query/1
uri_string:compose_query/2
uri_string:dissect_query/1