Function comrak::html::escape_href
source · pub fn escape_href(output: &mut dyn Write, buffer: &[u8]) -> Result<()>
Expand description
Writes buffer to output, escaping in a manner appropriate for URLs in HTML attributes.
Namely:
- U+0026 AMPERSAND & is rendered as &
- U+0027 APOSTROPHE ’ is rendered as '
- Alphanumeric and a range of non-URL safe characters.
The inclusion of characters like “%” in those which are not escaped is explained somewhat here:
https://github.com/github/cmark-gfm/blob/c32ef78bae851cb83b7ad52d0fbff880acdcd44a/src/houdini_href_e.c#L7-L31
In other words, if a CommonMark user enters:
[hi](https://ddg.gg/?q=a%20b)
We assume they actually want the query string “?q=a%20b”, a search for the string “a b”, rather than “?q=a%2520b”, a search for the literal string “a%20b”.