mirror of
https://github.com/certbot/certbot.git
synced 2026-06-03 22:08:07 -04:00
Merge pull request #2665 from letsencrypt/UnicodeError
Fixes unicode errors
This commit is contained in:
commit
8985c4684e
2 changed files with 24 additions and 4 deletions
|
|
@ -6,6 +6,7 @@ import logging
|
|||
import os
|
||||
import platform
|
||||
import re
|
||||
import six
|
||||
import socket
|
||||
import stat
|
||||
import subprocess
|
||||
|
|
@ -310,10 +311,13 @@ def enforce_domain_sanity(domain):
|
|||
# Unicode
|
||||
try:
|
||||
domain = domain.encode('ascii').lower()
|
||||
except UnicodeDecodeError:
|
||||
raise errors.ConfigurationError(
|
||||
"Internationalized domain names are not presently supported: {0}"
|
||||
.format(domain))
|
||||
except UnicodeError:
|
||||
error_fmt = (u"Internationalized domain names "
|
||||
"are not presently supported: {0}")
|
||||
if isinstance(domain, six.text_type):
|
||||
raise errors.ConfigurationError(error_fmt.format(domain))
|
||||
else:
|
||||
raise errors.ConfigurationError(str(error_fmt).format(domain))
|
||||
|
||||
# Remove trailing dot
|
||||
domain = domain[:-1] if domain.endswith('.') else domain
|
||||
|
|
|
|||
|
|
@ -323,5 +323,21 @@ class AddDeprecatedArgumentTest(unittest.TestCase):
|
|||
self.assertTrue("--old-option" not in stdout.getvalue())
|
||||
|
||||
|
||||
class EnforceDomainSanityTest(unittest.TestCase):
|
||||
"""Test enforce_domain_sanity."""
|
||||
|
||||
def _call(self, domain):
|
||||
from letsencrypt.le_util import enforce_domain_sanity
|
||||
return enforce_domain_sanity(domain)
|
||||
|
||||
def test_nonascii_str(self):
|
||||
self.assertRaises(errors.ConfigurationError, self._call,
|
||||
u"eichh\u00f6rnchen.example.com".encode("utf-8"))
|
||||
|
||||
def test_nonascii_unicode(self):
|
||||
self.assertRaises(errors.ConfigurationError, self._call,
|
||||
u"eichh\u00f6rnchen.example.com")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main() # pragma: no cover
|
||||
|
|
|
|||
Loading…
Reference in a new issue