Browse Source

[2053] Rewrite code to handle the root name

Mukund Sivaraman 12 years ago
parent
commit
fdcc93e8ee
2 changed files with 6 additions and 9 deletions
  1. 4 9
      src/lib/dns/labelsequence.cc
  2. 2 0
      src/lib/dns/tests/labelsequence_unittest.cc

+ 4 - 9
src/lib/dns/labelsequence.cc

@@ -114,14 +114,6 @@ LabelSequence::getHash(bool case_sensitive) const {
 
 std::string
 LabelSequence::toText(bool omit_final_dot) const {
-    if (name_.getLength() == 1) {
-        //
-        // Special handling for the root label.  We ignore omit_final_dot.
-        //
-        assert(name_.getLabelCount() == 1 && name_.ndata_[0] == '\0');
-        return (".");
-    }
-
     Name::NameString::const_iterator np = name_.ndata_.begin() +
         name_.offsets_[first_label_];
     const Name::NameString::const_iterator np_end = name_.ndata_.end();
@@ -140,7 +132,10 @@ LabelSequence::toText(bool omit_final_dot) const {
         count = *np++;
 
         if (count == 0) {
-            if (!omit_final_dot) {
+            // We've reached the "final dot".  If we've not dumped any
+            // character, the entire label sequence is the root name.
+            // In that case we don't omit the final dot.
+            if (!omit_final_dot || result.empty()) {
                 result.push_back('.');
             }
             break;

+ 2 - 0
src/lib/dns/tests/labelsequence_unittest.cc

@@ -293,6 +293,8 @@ TEST_F(LabelSequenceTest, isAbsolute) {
 }
 
 TEST_F(LabelSequenceTest, toText) {
+    EXPECT_EQ(".", ls7.toText());
+
     EXPECT_EQ("example.org.", ls1.toText());
     ls1.stripLeft(1);
     EXPECT_EQ("org.", ls1.toText());