Skip to content

Commit 43ad780

Browse files
committed
Ensure that empty TXT records always renders as ""
Instantiating an empty TXT record using Record.fromString() would previously render as a TXT without the empty string. Closes #254
1 parent c30db5a commit 43ad780

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/main/java/org/xbill/DNS/TXTBase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ protected void rdataFromString(Tokenizer st, Name origin) throws IOException {
7373
/** converts to a String */
7474
@Override
7575
protected String rrToString() {
76+
if (strings.isEmpty()) {
77+
// always return at least an empty quoted String
78+
return "\"\"";
79+
}
7680
StringBuilder sb = new StringBuilder();
7781
Iterator<byte[]> it = strings.iterator();
7882
while (it.hasNext()) {

src/test/java/org/xbill/DNS/RecordTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,4 +912,12 @@ void testSerializable() throws IOException {
912912
}
913913
}
914914
}
915+
916+
// https://github.com/dnsjava/dnsjava/issues/254
917+
@Test
918+
void testEmptyTXTSerialization() throws IOException {
919+
Name recordName = Name.fromString("name.name.");
920+
Record r = Record.fromString(recordName, Type.TXT, DClass.IN, 0, "", recordName);
921+
assertEquals("name.name.\t\t0\tIN\tTXT\t\"\"", r.toString());
922+
}
915923
}

0 commit comments

Comments
 (0)