]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2427] Handling of INITIAL_WS on the first line of included file
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 18 Dec 2012 12:03:42 +0000 (13:03 +0100)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 18 Dec 2012 12:03:42 +0000 (13:03 +0100)
Update the warning message to be usable for this case too. Also,
explicitly check and fix lexer again for this case.

src/lib/dns/master_lexer.cc
src/lib/dns/master_loader.cc
src/lib/dns/tests/master_lexer_unittest.cc
src/lib/dns/tests/master_loader_unittest.cc
src/lib/dns/tests/testdata/Makefile.am
src/lib/dns/tests/testdata/omitcheck.txt [new file with mode: 0644]

index a4f9a9ae7c6fae74b70f6045e9b89fbe54215833..e4ddedc64071a6b1e499c4a8eff17e8175b17b4d 100644 (file)
@@ -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
index b6edd4c7bd1ce9f8d76cfcb28a568d7f8a65e389..0848d5d4c58105353c51196d6a5bf62cdbc6bd5d 100644 (file)
@@ -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 ||
index 72dfde3d45869f83e46ae41b5c1d3db92265c87f..62ad79de6188077a12fe5e7925f2cd01d276bf5f 100644 (file)
@@ -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";
index ce60dca00863f36ef73be35901f64291e93aa9a0..934902d72a2973427a04e7736b7df08a6c111f23 100644 (file)
@@ -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");
+}
+
 }
index b72afff2be968199d5b0e98444a28a9758d3643a..52acb7c110eef6c5973f2bfa432a5a3d4333ec88 100644 (file)
@@ -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 $@ $<
diff --git a/src/lib/dns/tests/testdata/omitcheck.txt b/src/lib/dns/tests/testdata/omitcheck.txt
new file mode 100644 (file)
index 0000000..580cab4
--- /dev/null
@@ -0,0 +1 @@
+    1H  IN  A   192.0.2.1