Browse Source

[2442] make sure from-string version still throws InvalidRdataText on error.

JINMEI Tatuya 12 years ago
parent
commit
1780e7b66e

+ 10 - 7
src/lib/dns/rdata/generic/detail/txt_like.h

@@ -79,17 +79,20 @@ public:
 
 
     /// \brief Constructor from string.
     /// \brief Constructor from string.
     ///
     ///
-    /// <b>Exceptions</b>
-    ///
-    /// \c CharStringTooLong is thrown if the parameter string length exceeds
-    /// maximum.
-    /// \c InvalidRdataText is thrown if the method cannot process the
-    /// parameter data.
+    /// \throw CharStringTooLong the parameter string length exceeds maximum.
+    /// \throw InvalidRdataText the method cannot process the parameter data
     explicit TXTLikeImpl(const std::string& txtstr) {
     explicit TXTLikeImpl(const std::string& txtstr) {
         std::istringstream ss(txtstr);
         std::istringstream ss(txtstr);
         MasterLexer lexer;
         MasterLexer lexer;
         lexer.pushSource(ss);
         lexer.pushSource(ss);
-        buildFromTextHelper(lexer);
+
+        try {
+            buildFromTextHelper(lexer);
+        } catch (const MasterLexer::LexerError& ex) {
+            isc_throw(InvalidRdataText, "Failed to construct " <<
+                      RRType(typeCode) << " RDATA from " << txtstr << ": "
+                      << ex.what());
+        }
     }
     }
 
 
     TXTLikeImpl(MasterLexer& lexer, const Name*, MasterLoader::Options,
     TXTLikeImpl(MasterLexer& lexer, const Name*, MasterLoader::Options,

+ 1 - 1
src/lib/dns/tests/rdata_txt_like_unittest.cc

@@ -154,7 +154,7 @@ TYPED_TEST(Rdata_TXT_LIKE_Test, createFromText) {
 
 
     // The escape character makes the double quote a part of character-string,
     // The escape character makes the double quote a part of character-string,
     // so this is invalid input and should be rejected.
     // so this is invalid input and should be rejected.
-    EXPECT_THROW(TypeParam("\"Test-String\\\""), MasterLexer::LexerError);
+    EXPECT_THROW(TypeParam("\"Test-String\\\""), InvalidRdataText);
     EXPECT_THROW(TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
     EXPECT_THROW(TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS,
                            this->loader_cb), MasterLexer::LexerError);
                            this->loader_cb), MasterLexer::LexerError);
     EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType());
     EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType());