mirror of https://github.com/python/cpython
Support trailing dots in DNS names. Fixes #782510. Will backport to 2.3.
This commit is contained in:
parent
8db4403a76
commit
0d8e16c7ad
|
@ -150,10 +150,16 @@ class Codec(codecs.Codec):
|
||||||
raise UnicodeError, "unsupported error handling "+errors
|
raise UnicodeError, "unsupported error handling "+errors
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for label in dots.split(input):
|
labels = dots.split(input)
|
||||||
|
if labels and len(labels[-1])==0:
|
||||||
|
trailing_dot = '.'
|
||||||
|
del labels[-1]
|
||||||
|
else:
|
||||||
|
trailing_dot = ''
|
||||||
|
for label in labels:
|
||||||
result.append(ToASCII(label))
|
result.append(ToASCII(label))
|
||||||
# Join with U+002E
|
# Join with U+002E
|
||||||
return ".".join(result), len(input)
|
return ".".join(result)+trailing_dot, len(input)
|
||||||
|
|
||||||
def decode(self,input,errors='strict'):
|
def decode(self,input,errors='strict'):
|
||||||
|
|
||||||
|
@ -168,11 +174,17 @@ class Codec(codecs.Codec):
|
||||||
unicode(input, "ascii")
|
unicode(input, "ascii")
|
||||||
labels = input.split(".")
|
labels = input.split(".")
|
||||||
|
|
||||||
|
if labels and len(labels[-1]) == 0:
|
||||||
|
trailing_dot = u'.'
|
||||||
|
del labels[-1]
|
||||||
|
else:
|
||||||
|
trailing_dot = u''
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for label in labels:
|
for label in labels:
|
||||||
result.append(ToUnicode(label))
|
result.append(ToUnicode(label))
|
||||||
|
|
||||||
return u".".join(result), len(input)
|
return u".".join(result)+trailing_dot, len(input)
|
||||||
|
|
||||||
class StreamWriter(Codec,codecs.StreamWriter):
|
class StreamWriter(Codec,codecs.StreamWriter):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -524,6 +524,10 @@ class UnicodeTest(
|
||||||
# * strict decoding testing for all of the
|
# * strict decoding testing for all of the
|
||||||
# UTF8_ERROR cases in PyUnicode_DecodeUTF8
|
# UTF8_ERROR cases in PyUnicode_DecodeUTF8
|
||||||
|
|
||||||
|
def test_codecs_idna(self):
|
||||||
|
# Test whether trailing dot is preserved
|
||||||
|
self.assertEqual(u"www.python.org.".encode("idna"), "www.python.org.")
|
||||||
|
|
||||||
def test_codecs_errors(self):
|
def test_codecs_errors(self):
|
||||||
# Error handling (encoding)
|
# Error handling (encoding)
|
||||||
self.assertRaises(UnicodeError, u'Andr\202 x'.encode, 'ascii')
|
self.assertRaises(UnicodeError, u'Andr\202 x'.encode, 'ascii')
|
||||||
|
|
Loading…
Reference in New Issue