Imported Upstream version 17.23.2
[platform/upstream/libzypp.git] / zypp / repo / RepoVariables.cc
index 08957a3..cb140a9 100644 (file)
@@ -151,7 +151,7 @@ namespace zypp
 
        /** Valid var name char */
        bool isnamech( int ch ) const
-       { return ch == '_' || isalpha( ch ); }
+       { return ch == '_' || isalnum( ch ); }
 
        /** Scan for a valid variable starting at _vbeg (storing the values) */
        bool findVarEnd()
@@ -400,10 +400,15 @@ namespace zypp
       private:
        const std::string * _lookup( const std::string & name_r )
        {
+         // Safe guard in case the caller does not own a zypp instance. In this case
+         // getZYpp()->getTarget() in checkOverride would create a zypp instance which
+         // would clear the variables parsed so far.
+         auto guard { getZYpp() };
+
          if ( empty() )        // at init / after reset
          {
            // load user definitions from vars.d
-           filesystem::dirForEach( ZConfig::instance().systemRoot() / ZConfig::instance().varsPath(),
+           filesystem::dirForEach( ZConfig::instance().repoManagerRoot() / ZConfig::instance().varsPath(),
                                    filesystem::matchNoDots(), bind( &RepoVarsMap::parse, this, _1, _2 ) );
            // releasever_major/_minor are per default derived from releasever.
            // If releasever is userdefined, inject missing _major/_minor too.
@@ -548,10 +553,16 @@ namespace zypp
 
     Url RepoVariablesUrlReplacer::operator()( const Url & value ) const
     {
-      RepoVarExpand expand;
-      Url newurl( value );
-      newurl.setPathData( expand( value.getPathData(), RepoVarsMap::lookup ) );
-      newurl.setQueryString( expand( value.getQueryString(), RepoVarsMap::lookup ) );
+      Url::ViewOptions toReplace = value.getViewOptions() - url::ViewOption::WITH_USERNAME - url::ViewOption::WITH_PASSWORD;
+      const std::string & replaced( RepoVarExpand()( value.asString( toReplace ), RepoVarsMap::lookup ) );
+      Url newurl;
+      if ( !replaced.empty() )
+      {
+       newurl = replaced;
+       newurl.setUsername( value.getUsername( url::E_ENCODED ), url::E_ENCODED );
+       newurl.setPassword( value.getPassword( url::E_ENCODED ), url::E_ENCODED );
+       newurl.setViewOptions( value.getViewOptions() );
+      }
       return newurl;
     }
   } // namespace repo