Skip to content

Commit 6ed0fcf

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 f8c2648 commit 6ed0fcf

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ protected String rrToString() {
8282
sb.append(" ");
8383
}
8484
}
85-
return sb.toString();
85+
String s = sb.toString();
86+
// always return at least an empty quoted String
87+
return "".equals(s) ? "\"\"" : s;
8688
}
8789

8890
/**

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)