aaronsw/html2text — pull request #44 by dreikanter (2012-07-24 13:58:58+00:00)
Title: Fix: Escaping parenthesis in URLs to prevent links and image syntax from breaking

I found another bug: URLs containing unencoded brackets and parenthesis could break markdown links and images syntax when INLINE_LINKS = True. For example the following code:

...

will be transformed to

[...](http://example.com/;-)/page.html)

which will give the following MD transformation result (tested with python-markdown and dillinger.io):

...)/page.html

The same problem could appear with image source values. This case is not very common but some sites (e.g. MSDN) actively uses parenthesis in URLs.

I've fixed this by escaping parenthesis and brackets, so the result will produce correct HTML:

[...](http://example.com/;-\)/page.html)

This patch includes bugfix and new test case for URL escaping.