Commit e5d53f4b authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files
parents 11b5709d 055622f3
......@@ -38,26 +38,25 @@ using namespace isc::dns::rdata;
namespace isc {
namespace dns {
namespace {
// A helper function that strips off any comment placed at the end of an RR.
// A helper function that strips off any comment or whitespace at the end of
// an RR.
// This is an incomplete implementation, and cannot handle all such comments;
// it's considered a short term workaround to deal with some real world
// cases.
string
stripComment(string& s, const Exception& ex) {
stripLine(string& s, const Exception& ex) {
// Find any ';' in the text data, and locate the position of the last
// occurrence. Note that unless/until we support empty RDATA it
// shouldn't be placed at the beginning of the data.
const size_t pos_semicolon = s.rfind(';');
if (pos_semicolon == string::npos || pos_semicolon == 0) {
if (pos_semicolon == 0) {
throw ex;
} else if (pos_semicolon != string::npos) {
s.resize(pos_semicolon);
}
// Remove any trailing space and comments and return the resulting text.
const size_t pos_end_data = s.find_last_not_of(" /t", pos_semicolon - 1);
if (pos_end_data != string::npos) {
s.erase(pos_end_data + 1);
return (s);
}
throw ex;
// Remove any trailing whitespace return the resulting text.
s.resize(s.find_last_not_of(" \t") + 1);
return (s);
}
}
......@@ -145,10 +144,9 @@ masterLoad(istream& input, const Name& origin, const RRClass& zone_class,
rdata = createRdata(*rrtype, *rrclass, rdtext);
} catch (const Exception& ex) {
// If the parse for the RDATA fails, check if it has comments
// at the end, and if so, retry the conversion after stripping
// off the comment.
rdata = createRdata(*rrtype, *rrclass, stripComment(rdtext,
ex));
// or whitespace at the end, and if so, retry the conversion
// after stripping off the comment or whitespace
rdata = createRdata(*rrtype, *rrclass, stripLine(rdtext, ex));
}
} catch (const Exception& ex) {
isc_throw(MasterLoadError, "Invalid RR text at line " << line_count
......
......@@ -193,6 +193,54 @@ TEST_F(MasterLoadTest, loadRRWithCommentNoSpace) {
dnskey_rdata)));
}
TEST_F(MasterLoadTest, loadRRWithCommentEmptyComment) {
// Similar to the previous one, but there's no data after the ;
// It should still work.
rr_stream << "example.com. 3600 IN DNSKEY 256 3 7 "
"AwEAAaetidLzsKWUt4swWR8yu0wPHPiUi8LUsAD0QPWU+wzt89epO6tH "
"zkMBVDkC7qphQO2hTY4hHn9npWFRw5BYubE= ;\n";
masterLoad(rr_stream, origin, zclass, callback);
ASSERT_EQ(1, results.size());
EXPECT_EQ(0, results[0]->getRdataIterator()->getCurrent().compare(
*rdata::createRdata(RRType::DNSKEY(), zclass,
dnskey_rdata)));
}
TEST_F(MasterLoadTest, loadRRWithCommentEmptyCommentNoSpace) {
// Similar to the previous one, but there's no space before or after ;
// It should still work.
rr_stream << "example.com. 3600 IN DNSKEY 256 3 7 "
"AwEAAaetidLzsKWUt4swWR8yu0wPHPiUi8LUsAD0QPWU+wzt89epO6tH "
"zkMBVDkC7qphQO2hTY4hHn9npWFRw5BYubE=;\n";
masterLoad(rr_stream, origin, zclass, callback);
ASSERT_EQ(1, results.size());
EXPECT_EQ(0, results[0]->getRdataIterator()->getCurrent().compare(
*rdata::createRdata(RRType::DNSKEY(), zclass,
dnskey_rdata)));
}
TEST_F(MasterLoadTest, loadRRWithEOLWhitespace) {
// Test with whitespace after rdata
// It should still work.
rr_stream << "example.com. 3600 IN NSEC3PARAM 1 0 1 beef \n";
masterLoad(rr_stream, origin, zclass, callback);
ASSERT_EQ(1, results.size());
EXPECT_EQ(0, results[0]->getRdataIterator()->getCurrent().compare(
*rdata::createRdata(RRType::NSEC3PARAM(), zclass,
"1 0 1 beef")));
}
TEST_F(MasterLoadTest, loadRRWithEOLWhitespaceTab) {
// Similar to the previous one, tab instead of space.
// It should still work.
rr_stream << "example.com. 3600 IN NSEC3PARAM 1 0 1 beef\t\n";
masterLoad(rr_stream, origin, zclass, callback);
ASSERT_EQ(1, results.size());
EXPECT_EQ(0, results[0]->getRdataIterator()->getCurrent().compare(
*rdata::createRdata(RRType::NSEC3PARAM(), zclass,
"1 0 1 beef")));
}
TEST_F(MasterLoadTest, loadRRNoComment) {
// A semicolon in a character-string shouldn't confuse the parser.
rr_stream << "example.com. 3600 IN TXT \"aaa;bbb\"\n";
......
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