Commit bdc39037 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

[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.
parent eda75ca3
...@@ -127,6 +127,7 @@ MasterLexer::pushSource(const char* filename, std::string* error) { ...@@ -127,6 +127,7 @@ MasterLexer::pushSource(const char* filename, std::string* error) {
impl_->source_ = impl_->sources_.back().get(); impl_->source_ = impl_->sources_.back().get();
impl_->has_previous_ = false; impl_->has_previous_ = false;
impl_->last_was_eol_ = true;
return (true); return (true);
} }
...@@ -135,6 +136,7 @@ MasterLexer::pushSource(std::istream& input) { ...@@ -135,6 +136,7 @@ MasterLexer::pushSource(std::istream& input) {
impl_->sources_.push_back(InputSourcePtr(new InputSource(input))); impl_->sources_.push_back(InputSourcePtr(new InputSource(input)));
impl_->source_ = impl_->sources_.back().get(); impl_->source_ = impl_->sources_.back().get();
impl_->has_previous_ = false; impl_->has_previous_ = false;
impl_->last_was_eol_ = true;
} }
void void
......
...@@ -406,8 +406,8 @@ MasterLoader::MasterLoaderImpl::handleInitialToken() { ...@@ -406,8 +406,8 @@ MasterLoader::MasterLoaderImpl::handleInitialToken() {
"place of initial whitespace"); "place of initial whitespace");
} else if (!previous_name_) { } else if (!previous_name_) {
callbacks_.warning(lexer_.getSourceName(), lexer_.getSourceLine(), callbacks_.warning(lexer_.getSourceName(), lexer_.getSourceLine(),
"Ambiguous previous name for use in place of " "Owner name omitted around $INCLUDE, the result "
"initial whitespace"); "might not be as expected");
} }
return (next_token); return (next_token);
} else if (initial_token.getType() == MasterToken::STRING || } else if (initial_token.getType() == MasterToken::STRING ||
......
...@@ -252,6 +252,22 @@ TEST_F(MasterLexerTest, ungetRealOptions) { ...@@ -252,6 +252,22 @@ TEST_F(MasterLexerTest, ungetRealOptions) {
lexer.getNextToken(MasterLexer::INITIAL_WS).getType()); 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 only one token can be ungotten
TEST_F(MasterLexerTest, ungetTwice) { TEST_F(MasterLexerTest, ungetTwice) {
ss << "\n"; ss << "\n";
......
...@@ -569,8 +569,8 @@ TEST_F(MasterLoaderTest, includeAndInitialWS) { ...@@ -569,8 +569,8 @@ TEST_F(MasterLoaderTest, includeAndInitialWS) {
EXPECT_TRUE(errors_.empty()); EXPECT_TRUE(errors_.empty());
EXPECT_EQ(1, warnings_.size()); EXPECT_EQ(1, warnings_.size());
checkCallbackMessage(warnings_.at(0), checkCallbackMessage(warnings_.at(0),
"Ambiguous previous name for use in place of initial" "Owner name omitted around $INCLUDE, the result might "
" whitespace", 3); "not be as expected", 3);
checkARR("xyz.example.org"); checkARR("xyz.example.org");
checkBasicRRs(); checkBasicRRs();
checkARR("xyz.example.org"); checkARR("xyz.example.org");
...@@ -772,7 +772,7 @@ TEST_F(MasterLoaderTest, noEOLN) { ...@@ -772,7 +772,7 @@ TEST_F(MasterLoaderTest, noEOLN) {
loader_->load(); loader_->load();
EXPECT_TRUE(loader_->loadedSucessfully()); EXPECT_TRUE(loader_->loadedSucessfully());
EXPECT_TRUE(errors_.empty()) << errors_[0]; EXPECT_TRUE(errors_.empty());
// There should be one warning about the EOLN // There should be one warning about the EOLN
EXPECT_EQ(1, warnings_.size()); EXPECT_EQ(1, warnings_.size());
checkRR("example.org", RRType::SOA(), "ns1.example.org. " checkRR("example.org", RRType::SOA(), "ns1.example.org. "
...@@ -794,4 +794,22 @@ TEST_F(MasterLoaderTest, noPreviousName) { ...@@ -794,4 +794,22 @@ TEST_F(MasterLoaderTest, noPreviousName) {
EXPECT_TRUE(warnings_.empty()); 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");
}
} }
...@@ -173,6 +173,7 @@ EXTRA_DIST += tsig_verify10.spec ...@@ -173,6 +173,7 @@ EXTRA_DIST += tsig_verify10.spec
EXTRA_DIST += example.org EXTRA_DIST += example.org
EXTRA_DIST += broken.zone EXTRA_DIST += broken.zone
EXTRA_DIST += origincheck.txt EXTRA_DIST += origincheck.txt
EXTRA_DIST += omitcheck.txt
.spec.wire: .spec.wire:
$(PYTHON) $(top_builddir)/src/lib/util/python/gen_wiredata.py -o $@ $< $(PYTHON) $(top_builddir)/src/lib/util/python/gen_wiredata.py -o $@ $<
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment