Browse Source

[2427] Handling of INITIAL_WS on the first line of included file

Update the warning message to be usable for this case too. Also,
explicitly check and fix lexer again for this case.
Michal 'vorner' Vaner 12 years ago
parent
commit
bdc390376f

+ 2 - 0
src/lib/dns/master_lexer.cc

@@ -127,6 +127,7 @@ MasterLexer::pushSource(const char* filename, std::string* error) {
 
     impl_->source_ = impl_->sources_.back().get();
     impl_->has_previous_ = false;
+    impl_->last_was_eol_ = true;
     return (true);
 }
 
@@ -135,6 +136,7 @@ MasterLexer::pushSource(std::istream& input) {
     impl_->sources_.push_back(InputSourcePtr(new InputSource(input)));
     impl_->source_ = impl_->sources_.back().get();
     impl_->has_previous_ = false;
+    impl_->last_was_eol_ = true;
 }
 
 void

+ 2 - 2
src/lib/dns/master_loader.cc

@@ -406,8 +406,8 @@ MasterLoader::MasterLoaderImpl::handleInitialToken() {
                       "place of initial whitespace");
         } else if (!previous_name_) {
             callbacks_.warning(lexer_.getSourceName(), lexer_.getSourceLine(),
-                               "Ambiguous previous name for use in place of "
-                               "initial whitespace");
+                               "Owner name omitted around $INCLUDE, the result "
+                               "might not be as expected");
         }
         return (next_token);
     } else if (initial_token.getType() == MasterToken::STRING ||

+ 16 - 0
src/lib/dns/tests/master_lexer_unittest.cc

@@ -252,6 +252,22 @@ TEST_F(MasterLexerTest, ungetRealOptions) {
               lexer.getNextToken(MasterLexer::INITIAL_WS).getType());
 }
 
+// Check the initial whitespace is found even in the first line of included
+// file
+TEST_F(MasterLexerTest, includeAndInitialWS) {
+    ss << "    \n";
+    lexer.pushSource(ss);
+
+    stringstream ss2;
+    ss2 << "    \n";
+
+    EXPECT_EQ(MasterToken::INITIAL_WS,
+              lexer.getNextToken(MasterLexer::INITIAL_WS).getType());
+    lexer.pushSource(ss2);
+    EXPECT_EQ(MasterToken::INITIAL_WS,
+              lexer.getNextToken(MasterLexer::INITIAL_WS).getType());
+}
+
 // Test only one token can be ungotten
 TEST_F(MasterLexerTest, ungetTwice) {
     ss << "\n";

+ 21 - 3
src/lib/dns/tests/master_loader_unittest.cc

@@ -569,8 +569,8 @@ TEST_F(MasterLoaderTest, includeAndInitialWS) {
     EXPECT_TRUE(errors_.empty());
     EXPECT_EQ(1, warnings_.size());
     checkCallbackMessage(warnings_.at(0),
-                         "Ambiguous previous name for use in place of initial"
-                         " whitespace", 3);
+                         "Owner name omitted around $INCLUDE, the result might "
+                         "not be as expected", 3);
     checkARR("xyz.example.org");
     checkBasicRRs();
     checkARR("xyz.example.org");
@@ -772,7 +772,7 @@ TEST_F(MasterLoaderTest, noEOLN) {
 
     loader_->load();
     EXPECT_TRUE(loader_->loadedSucessfully());
-    EXPECT_TRUE(errors_.empty()) << errors_[0];
+    EXPECT_TRUE(errors_.empty());
     // There should be one warning about the EOLN
     EXPECT_EQ(1, warnings_.size());
     checkRR("example.org", RRType::SOA(), "ns1.example.org. "
@@ -794,4 +794,22 @@ TEST_F(MasterLoaderTest, noPreviousName) {
     EXPECT_TRUE(warnings_.empty());
 }
 
+// Check we warn if the first RR in an included file has omitted name
+TEST_F(MasterLoaderTest, previousInInclude) {
+    const string input("www 1H  IN  A   192.0.2.1\n"
+                       "$INCLUDE " TEST_DATA_SRCDIR "/omitcheck.txt\n");
+    stringstream ss(input);
+    setLoader(ss, Name("example.org"), RRClass::IN(),
+              MasterLoader::MANY_ERRORS);
+    loader_->load();
+    EXPECT_TRUE(loader_->loadedSucessfully());
+    EXPECT_TRUE(errors_.empty());
+    // There should be one warning about the EOLN
+    EXPECT_EQ(1, warnings_.size());
+    checkCallbackMessage(warnings_.at(0), "Owner name omitted around "
+                         "$INCLUDE, the result might not be as expected", 1);
+    checkARR("www.example.org");
+    checkARR("www.example.org");
+}
+
 }

+ 1 - 0
src/lib/dns/tests/testdata/Makefile.am

@@ -173,6 +173,7 @@ EXTRA_DIST += tsig_verify10.spec
 EXTRA_DIST += example.org
 EXTRA_DIST += broken.zone
 EXTRA_DIST += origincheck.txt
+EXTRA_DIST += omitcheck.txt
 
 .spec.wire:
 	$(PYTHON) $(top_builddir)/src/lib/util/python/gen_wiredata.py -o $@ $<

+ 1 - 0
src/lib/dns/tests/testdata/omitcheck.txt

@@ -0,0 +1 @@
+    1H  IN  A   192.0.2.1