Skip to content

Commit

Permalink
Handle quoted strings followed by unquoted strings in TXT records
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdalitz committed Dec 21, 2020
1 parent 8b2952c commit 62d51f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/dnsruby/resource/TXT.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,17 @@ def TXT.parse(input)
end
else
if (seen_strings && !in_string)
next
if (c == ";")
# Comment in zone file!
return strings
end
if (c != " " && c != "\t")
in_string = true
count+=1
strings[count] = ""
else
next
end
end
if (pos == 0)
unquoted = true
Expand Down
8 changes: 7 additions & 1 deletion test/tc_rr-txt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ def test_nasty_txt

r1 = RR.create("auto._domainkey.cacert.org. 43200 IN TXT \"v=DKIM1\;g=*\;k=rsa\;p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDNFxiNr+NHJwih3OPhGr4iwLE+BBDu72YrMSzUnU1FF50CW7iOtuhg796UZ6xrZ5VuhAix6YmmzcvF2UxYzoD/XpfZ4MzBu0ND4/nkt9/YOTyIBzwQqn9uMNve0Y76Zsel89dIJtOI+y+lfnFExV0jKwe53gzmxMVpMSSCcZPGwIDAQAB\" ; ----- DKIM auto for cacert.org")
r2 = RR.create("auto._domainkey.cacert.org. 43200 IN TXT \"v=DKIM1;g=*;k=rsa;p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDNFxiNr+NHJwih3OPhGr4iwLE+BBDu72YrMSzUnU1FF50CW7iOtuhg796UZ6xrZ5VuhAix6YmmzcvF2UxYzoD/XpfZ4MzBu0ND4/nkt9/YOTyIBzwQqn9uMNve0Y76Zsel89dIJtOI+y+lfnFExV0jKwe53gzmxMVpMSSCcZPGwIDAQAB\"")
assert(r1.to_s == r2.to_s)
assert_equal(r1.to_s, r2.to_s)
end

def test_quote_and_unquoted
t = Dnsruby::RR::TXT.parse '"a" b'
assert_equal("a", t[0])
assert_equal("b", t[1])
end

end

0 comments on commit 62d51f0

Please sign in to comment.