diff options
Diffstat (limited to 'rfc1035label')
-rw-r--r-- | rfc1035label/label.go | 8 | ||||
-rw-r--r-- | rfc1035label/label_test.go | 4 |
2 files changed, 11 insertions, 1 deletions
diff --git a/rfc1035label/label.go b/rfc1035label/label.go index 5a67d7c..561008e 100644 --- a/rfc1035label/label.go +++ b/rfc1035label/label.go @@ -100,6 +100,14 @@ func labelsFromBytes(buf []byte) ([]string, error) { for { if pos >= len(buf) { + // interpret label without trailing zero-length byte as a partial + // domain name field as per RFC 4704 Section 4.2 + if label != "" { + labels = append(labels, label) + + return labels, nil + } + break } length := int(buf[pos]) diff --git a/rfc1035label/label_test.go b/rfc1035label/label_test.go index 2e20736..865b41a 100644 --- a/rfc1035label/label_test.go +++ b/rfc1035label/label_test.go @@ -28,7 +28,9 @@ func TestLabelsFromBytesZeroLength(t *testing.T) { require.Equal(t, []byte{}, labels.ToBytes()) } -func TestLabelsFromBytesWithoutZeroLength(t *testing.T) { +func TestLabelsFromBytesPartialDomainName(t *testing.T) { + // Partial domain name without trailing zero-length byte as per RFC 4704 + // Section 4.2 expected := []byte{ 0x8, 'h', 'o', 's', 't', 'n', 'a', 'm', 'e', } |