Skip to content

Commit

Permalink
fix: RR value parsing when label contains a record type (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Jan 21, 2024
1 parent ff9f18d commit 0ca9b8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,12 @@ func TestMainResolveIPs(t *testing.T) {
assert.Nil(t, err)
assert.Regexp(t, regexp.MustCompile(`core1.fmt2.he.net. .* A .* \(core1.fmt2.he.net.\)`), out.String())
}

func TestMainQueryDomainWithRRType(t *testing.T) {
out, err := run(
"NS.network",
"A",
)
assert.Nil(t, err)
assert.Regexp(t, regexp.MustCompile(`NS.network. .* A .*`), out.String())
}
8 changes: 7 additions & 1 deletion output/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ func (e *Entry) parseRR(a dns.RR, opts *cli.Flags) *RR {
e.existingRRs = make(map[string]bool)
}

val := strings.TrimSpace(strings.Join(strings.Split(a.String(), dns.TypeToString[a.Header().Rrtype])[1:], ""))
val := a.String()
for _, cut := range []string{a.Header().Name, strconv.Itoa(int(a.Header().Ttl)), dns.ClassToString[a.Header().Class], dns.TypeToString[a.Header().Rrtype]} {
val = strings.TrimSpace(
strings.TrimPrefix(val, cut),
)
}

rrSignature := fmt.Sprintf("%s %d %s %s %s", a.Header().Name, a.Header().Ttl, dns.TypeToString[a.Header().Rrtype], val, e.Server)
// Skip if we've already printed this RR
if ok := e.existingRRs[rrSignature]; ok {
Expand Down

0 comments on commit 0ca9b8b

Please sign in to comment.