Skip to content

Commit aa6cf9e

Browse files
committed
idn-hostname validation.
1 parent 17fb9cb commit aa6cf9e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

jsonschema/_format.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,20 @@ def is_host_name(instance):
218218
return True
219219

220220

221+
try:
222+
# The built-in `idna` codec only implements RFC 3890, so we go elsewhere.
223+
import idna
224+
except ImportError:
225+
pass
226+
else:
227+
@_checks_drafts(draft7="idn-hostname", raises=idna.IDNAError)
228+
def is_idn_host_name(instance):
229+
if not isinstance(instance, str_types):
230+
return True
231+
idna.encode(instance)
232+
return True
233+
234+
221235
try:
222236
import rfc3987
223237
except ImportError:

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ install_requires =
3333

3434
[options.extras_require]
3535
format =
36+
idna
3637
jsonpointer>1.13
3738
rfc3987
3839
strict-rfc3339

0 commit comments

Comments
 (0)