Skip to content

Commit 28f8eba

Browse files
committed
Improve docs for URI.encode/2
1 parent b3b1420 commit 28f8eba

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/elixir/lib/uri.ex

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,21 +362,23 @@ defmodule URI do
362362
end
363363

364364
@doc """
365-
Percent-escapes all characters that require escaping in `string`.
365+
Percent-encodes all characters that require escaping in `string`.
366366
367-
This means reserved characters, such as `:` and `/`, and the
368-
so-called unreserved characters, which have the same meaning both
369-
escaped and unescaped, won't be escaped by default.
367+
By default, this function is meant to escape the whole URI, and
368+
therefore it will escape all characters which are foreign to the
369+
URI specification. Reserved characters (such as `:` and `/`) or
370+
unreserved (such as letters and numbers) are not escaped.
370371
371-
See `encode_www_form/1` if you are interested in escaping reserved
372-
characters too.
373-
374-
This function also accepts a `predicate` function as an optional
372+
Because different components of a URI require different escaping
373+
rules, this function also accepts a `predicate` function as an optional
375374
argument. If passed, this function will be called with each byte
376375
in `string` as its argument and should return a truthy value (anything other
377-
than `false` or `nil`) if the given byte should be left as is, or return a
378-
falsy value (`false` or `nil`) if the character should be escaped. Defaults
379-
to `URI.char_unescaped?/1`.
376+
than `false` or `nil`) if the given byte should be left as is, or
377+
return a falsy value (`false` or `nil`) if the character should be
378+
escaped. Defaults to `URI.char_unescaped?/1`.
379+
380+
See `encode_www_form/1` if you are interested in escaping reserved
381+
characters too.
380382
381383
## Examples
382384

0 commit comments

Comments
 (0)