mitsuhiko/werkzeug — pull request #644 by brmzkw (2014-12-18 16:16:43+00:00)
Title: Catch UnicodeDecodeError, fixes #640

Fix proposal for issue #640

`_encode_idna` is called from four places in werkzeug

```bash
$> git grep _encode_idna | grep -vE '(import|def)'
werkzeug/_internal.py: domain = _encode_idna(domain)
werkzeug/routing.py: server_name = _encode_idna(server_name)
werkzeug/urls.py: rv = _encode_idna(rv)
werkzeug/wsgi.py: return _encode_idna(hostname)
```

* **_internal.py**: called by `_make_cookie_domain`. I don't know when `_make_cookie_domain` is called or why. The patch proposed doesn't fix a issue here.

* **routing.py**: called by `Map.bind` with `server_name` as attr. The patch sets `server_name` to `None` if `_encode_idna` fails. I don't know if it generates side effects.

* **urls.py**: called by `BaseURL.ascii_host`. The patch doesn't fix anything here, I don't know if it needs to.

* **wsgi.py**: called by `host_is_trusted` on both arguments `hostname` and `trusted_list`. If `hostname` is not only ASCII, `host_is_trusted` returns False. If an entry of `host_is_trusted` is not only ASCII, the comparison against it is skipped.