You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2014/07/03 22:25:28 UTC

svn commit: r1607739 - in /qpid/trunk/qpid/cpp/src: qpid/broker/Selector.cpp qpid/broker/SelectorExpression.cpp qpid/broker/SelectorToken.cpp tests/Selector.cpp

Author: astitcher
Date: Thu Jul  3 20:25:28 2014
New Revision: 1607739

URL: http://svn.apache.org/r1607739
Log:
QPID-5874: Treat all empty selectors sensibly

Modified:
    qpid/trunk/qpid/cpp/src/qpid/broker/Selector.cpp
    qpid/trunk/qpid/cpp/src/qpid/broker/SelectorExpression.cpp
    qpid/trunk/qpid/cpp/src/qpid/broker/SelectorToken.cpp
    qpid/trunk/qpid/cpp/src/tests/Selector.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Selector.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Selector.cpp?rev=1607739&r1=1607738&r2=1607739&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Selector.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Selector.cpp Thu Jul  3 20:25:28 2014
@@ -229,13 +229,8 @@ bool Selector::filter(const Message& msg
     return eval(env);
 }
 
-namespace {
-const boost::shared_ptr<Selector> NULL_SELECTOR = boost::shared_ptr<Selector>();
-}
-
 boost::shared_ptr<Selector> returnSelector(const string& e)
 {
-    if (e.empty()) return NULL_SELECTOR;
     return boost::shared_ptr<Selector>(new Selector(e));
 }
 

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/SelectorExpression.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/SelectorExpression.cpp?rev=1607739&r1=1607738&r2=1607739&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/SelectorExpression.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/SelectorExpression.cpp Thu Jul  3 20:25:28 2014
@@ -728,6 +728,16 @@ friend TopExpression* TopExpression::par
 
 string error;
 
+Expression* selectorExpression(Tokeniser& tokeniser)
+{
+    if ( tokeniser.nextToken().type==T_EOS ) {
+        return (new Literal(true));
+    }
+    tokeniser.returnTokens();
+    std::auto_ptr<Expression> e(orExpression(tokeniser));
+    return e.release();
+}
+
 Expression* orExpression(Tokeniser& tokeniser)
 {
     std::auto_ptr<Expression> e(andExpression(tokeniser));
@@ -991,7 +1001,7 @@ TopExpression* TopExpression::parse(cons
     string::const_iterator e = exp.end();
     Tokeniser tokeniser(s,e);
     Parse parse;
-    std::auto_ptr<Expression> b(parse.orExpression(tokeniser));
+    std::auto_ptr<Expression> b(parse.selectorExpression(tokeniser));
     if (!b.get()) {
         throwParseError(tokeniser, parse.error);
     }

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/SelectorToken.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/SelectorToken.cpp?rev=1607739&r1=1607738&r2=1607739&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/SelectorToken.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/SelectorToken.cpp Thu Jul  3 20:25:28 2014
@@ -44,14 +44,6 @@ TokenException::TokenException(const std
     range_error(msg)
 {}
 
-// Not much of a parser...
-void skipWS(std::string::const_iterator& s, std::string::const_iterator& e)
-{
-    while ( s!=e && std::isspace(*s) ) {
-        ++s;
-    }
-}
-
 // Lexically, reserved words are a subset of identifiers
 // so we parse an identifier first then check if it is a reserved word and
 // convert it if it is a reserved word
@@ -173,6 +165,7 @@ bool tokenise(std::string::const_iterato
     switch (state) {
     case START:
         if (t==e) {tok = Token(T_EOS, s, END); return true;}
+        else if (std::isspace(*t)) {++t; ++s; continue;}
         else switch (*t) {
         case '(': tokType = T_LPAREN; state = ACCEPT_INC; continue;
         case ')': tokType = T_RPAREN; state = ACCEPT_INC; continue;
@@ -281,8 +274,6 @@ const Token& Tokeniser::nextToken()
     // Don't extend stream of tokens further than the end of stream;
     if ( tokp>0 && tokens[tokp-1].type==T_EOS ) return tokens[tokp-1];
 
-    skipWS(inp, inEnd);
-
     tokens.push_back(Token());
     Token& tok = tokens[tokp++];
 

Modified: qpid/trunk/qpid/cpp/src/tests/Selector.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/Selector.cpp?rev=1607739&r1=1607738&r2=1607739&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/Selector.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/Selector.cpp Thu Jul  3 20:25:28 2014
@@ -151,6 +151,7 @@ void verifyTokeniserFail(TokeniseF t, co
 QPID_AUTO_TEST_CASE(tokeniseSuccess)
 {
     verifyTokeniserSuccess(&tokenise, "", qb::T_EOS, "", "");
+    verifyTokeniserSuccess(&tokenise, " ", qb::T_EOS, "", "");
     verifyTokeniserSuccess(&tokenise, "null_123+blah", qb::T_IDENTIFIER, "null_123", "+blah");
     verifyTokeniserSuccess(&tokenise, "\"null-123\"+blah", qb::T_IDENTIFIER, "null-123", "+blah");
     verifyTokeniserSuccess(&tokenise, "\"This is an \"\"odd!\"\" identifier\"+blah", qb::T_IDENTIFIER, "This is an \"odd!\" identifier", "+blah");
@@ -344,6 +345,8 @@ QPID_AUTO_TEST_CASE(simpleEval)
     env.set("A", "Bye, bye cruel world");
     env.set("B", "hello kitty");
 
+    BOOST_CHECK(qb::Selector("").eval(env));
+    BOOST_CHECK(qb::Selector(" ").eval(env));
     BOOST_CHECK(qb::Selector("A is not null").eval(env));
     BOOST_CHECK(!qb::Selector("A is null").eval(env));
     BOOST_CHECK(!qb::Selector("A = C").eval(env));



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org