Skip to content

Commit e11700f

Browse files
lassebmjstasiak
authored andcommitted
Fix UTF-8 multibyte name compression
1 parent 6fe8132 commit e11700f

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

test_zeroconf.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ def test_parse_own_packet_question(self):
115115
r._CLASS_IN))
116116
r.DNSIncoming(generated.packet())
117117

118+
def test_parse_own_packet_response(self):
119+
generated = r.DNSOutgoing(r._FLAGS_QR_RESPONSE)
120+
generated.add_answer_at_time(r.DNSService(
121+
"æøå.local.", r._TYPE_SRV, r._CLASS_IN, r._DNS_TTL, 0, 0, 80, "foo.local."), 0)
122+
parsed = r.DNSIncoming(generated.packet())
123+
self.assertEqual(len(generated.answers), 1)
124+
self.assertEqual(len(generated.answers), len(parsed.answers))
125+
118126
def test_match_question(self):
119127
generated = r.DNSOutgoing(r._FLAGS_QR_QUERY)
120128
question = r.DNSQuestion("testname.local.", r._TYPE_SRV, r._CLASS_IN)
@@ -705,7 +713,7 @@ def test_integration_with_listener_class(self):
705713
subtype_name = "My special Subtype"
706714
type_ = "_http._tcp.local."
707715
subtype = subtype_name + "._sub." + type_
708-
name = "xxxyyy"
716+
name = "xxxyyyæøå"
709717
registration_name = "%s.%s" % (name, type_)
710718

711719
class MyListener:

zeroconf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,9 @@ def write_name(self, name):
944944
count = len(name_suffices)
945945

946946
# note the new names we are saving into the packet
947+
name_length = len(name.encode('utf-8'))
947948
for suffix in name_suffices[:count]:
948-
self.names[suffix] = self.size + len(name) - len(suffix) - 1
949+
self.names[suffix] = self.size + name_length - len(suffix.encode('utf-8')) - 1
949950

950951
# write the new names out.
951952
for part in parts[:count]:

0 commit comments

Comments
 (0)