diff --git a/tests/repo/RepoVariables_test.cc b/tests/repo/RepoVariables_test.cc index eec023e966..25c88f4d3c 100644 --- a/tests/repo/RepoVariables_test.cc +++ b/tests/repo/RepoVariables_test.cc @@ -125,7 +125,7 @@ void helperGenRepVarExpandResults() } } -void RepVarExpandTest( const std::string & string_r, const std::string & allUndef_r, const std::string & allDef_r ) +void RepVarExpandTest( const std::string & string_r, const std::string & allUndef_r, const std::string & allDef_r, bool hasVars=true ) { std::map vartable; bool varsoff = true; @@ -140,6 +140,7 @@ void RepVarExpandTest( const std::string & string_r, const std::string & allUnde return &val; }; + BOOST_CHECK_EQUAL( repo::hasRepoVarsEmbedded( string_r ), hasVars ); varsoff = true; BOOST_CHECK_EQUAL( repo::RepoVarExpand()( string_r, varLookup ), allUndef_r ); varsoff = false; @@ -147,10 +148,10 @@ void RepVarExpandTest( const std::string & string_r, const std::string & allUnde } BOOST_AUTO_TEST_CASE(RepVarExpand) -{ // ( STRING , REPLACED_all_vars_undef , REPLACED_all_vars_defined ) - RepVarExpandTest( "" , "" , "" ); - RepVarExpandTest( "$" , "$" , "$" ); - RepVarExpandTest( "$${}" , "$${}" , "$${}" ); +{ // ( STRING , REPLACED_all_vars_undef , REPLACED_all_vars_defined STRING has Vars) + RepVarExpandTest( "" , "" , "" , false ); + RepVarExpandTest( "$" , "$" , "$" , false ); + RepVarExpandTest( "$${}" , "$${}" , "$${}" , false ); RepVarExpandTest( "$_:" , "$_:" , "[_]:" ); RepVarExpandTest( "$_A:" , "$_A:" , "[_A]:" ); RepVarExpandTest( "$_A_:" , "$_A_:" , "[_A_]:" ); @@ -163,7 +164,7 @@ BOOST_AUTO_TEST_CASE(RepVarExpand) RepVarExpandTest( "${C:+a\\${B\\}ba}" , "" , "a${B}ba" ); RepVarExpandTest( "${C:+a\\${B}ba}" , "ba}" , "a${Bba}" ); RepVarExpandTest( "${C:-a$Bba}" , "a$Bba" , "[C]" ); - RepVarExpandTest( "${_A_B\\}" , "${_A_B\\}" , "${_A_B\\}" ); + RepVarExpandTest( "${_A_B\\}" , "${_A_B\\}" , "${_A_B\\}" , false ); RepVarExpandTest( "${_A_B}" , "${_A_B}" , "[_A_B]" ); RepVarExpandTest( "\\${_A_B}" , "\\${_A_B}" , "\\[_A_B]" ); RepVarExpandTest( "__${D:+\\$X--{${E:-==\\$X{o\\}==} }--}__\\${B}${}__", "__--}__\\${B}${}__" , "__$X--{[E] --}__\\[B]${}__" ); diff --git a/zypp/repo/RepoVariables.cc b/zypp/repo/RepoVariables.cc index d6677387fe..4b4a219db7 100644 --- a/zypp/repo/RepoVariables.cc +++ b/zypp/repo/RepoVariables.cc @@ -381,6 +381,9 @@ namespace zypp } // namespace /////////////////////////////////////////////////////////////////// + bool hasRepoVarsEmbedded( const std::string & str_r ) + { return FindVar( str_r, 0 ).nextVar(); } + std::string RepoVarExpand::operator()( const std::string & value_r, VarRetriever varRetriever_r ) const { return expand( value_r, 0, varRetriever_r ); } diff --git a/zypp/repo/RepoVariables.h b/zypp/repo/RepoVariables.h index 31e47fb063..a67b22dce1 100644 --- a/zypp/repo/RepoVariables.h +++ b/zypp/repo/RepoVariables.h @@ -22,6 +22,9 @@ namespace zypp /////////////////////////////////////////////////////////////////// namespace repo { + /** Return whether \a str_r has embedded variables. */ + bool hasRepoVarsEmbedded( const std::string & str_r ); + /////////////////////////////////////////////////////////////////// /// \class RepoVarExpand /// \brief Functor expanding repo variables in a string