Don't allow an alias to start with '.' (bnc #473834)
authorJán Kupec <jkupec@suse.cz>
Fri, 4 Dec 2009 13:43:43 +0000 (14:43 +0100)
committerJán Kupec <jkupec@suse.cz>
Fri, 4 Dec 2009 13:43:43 +0000 (14:43 +0100)
zypp/RepoManager.cc
zypp/repo/RepoException.cc
zypp/repo/RepoException.h

index 7f0cc0e..0616261 100644 (file)
@@ -285,12 +285,22 @@ namespace zypp
   {
     if ( info.alias().empty() )
       ZYPP_THROW( RepoNoAliasException() );
+    // bnc #473834. Maybe we can match the alias against a regex to define
+    // and check for valid aliases
+    if ( info.alias()[0] == '.')
+      ZYPP_THROW(RepoInvalidAliasException(
+         info, _("Repository alias cannot start with dot.")));
   }
 
   inline void assert_alias( const ServiceInfo & info )
   {
     if ( info.alias().empty() )
       ZYPP_THROW( ServiceNoAliasException() );
+    // bnc #473834. Maybe we can match the alias against a regex to define
+    // and check for valid aliases
+    if ( info.alias()[0] == '.')
+      ZYPP_THROW(ServiceInvalidAliasException(
+         info, _("Service alias cannot start with dot.")));
   }
 
   ////////////////////////////////////////////////////////////////////////////
index 586e5ef..5543c43 100644 (file)
@@ -64,6 +64,7 @@ namespace zypp
     DEF_CTORS( RepoNotCachedException,      "Repository is not cached" );
     DEF_CTORS( RepoNoUrlException,          "Repository has no or invalid url defined." );
     DEF_CTORS( RepoNoAliasException,        "Repository has no alias defined." );
+    DEF_CTORS( RepoInvalidAliasException,   "Repository has an invalid alias." );
     DEF_CTORS( RepoNotFoundException,       "Repository not found." );
     DEF_CTORS( RepoAlreadyExistsException,  "Repository already exists." );
     DEF_CTORS( RepoUnknownTypeException,    "Repository type can't be determined." );
@@ -111,6 +112,7 @@ namespace zypp
     CLASS::CLASS( const ServiceInfo & service_r, const std::string & msg_r ) : ServiceException( service_r, msg_r ) {}
 
     DEF_CTORS( ServiceNoAliasException,       "Service has no alias defined." );
+    DEF_CTORS( ServiceInvalidAliasException,  "Service has an invalid alias." );
     DEF_CTORS( ServiceAlreadyExistsException, "Service already exists." );
     DEF_CTORS( ServiceNoUrlException,         "Service has no or invalid url defined." );
 
index d910ebd..50b75d3 100644 (file)
@@ -98,6 +98,18 @@ namespace zypp
     };
 
     /**
+     * Thrown when the repo alias is found to be invalid.
+     */
+    class RepoInvalidAliasException : public RepoException
+    {
+    public:
+      RepoInvalidAliasException();
+      RepoInvalidAliasException( const std::string & msg_r );
+      RepoInvalidAliasException( const RepoInfo & info );
+      RepoInvalidAliasException( const RepoInfo & info, const std::string & msg_r );
+    };
+
+    /**
      * thrown when it was impossible to
      * match a repository
      */
@@ -194,6 +206,18 @@ namespace zypp
         ServiceNoAliasException( const ServiceInfo & service_r, const std::string & msg_r );
     };
 
+    /**
+     * Thrown when the repo alias is found to be invalid.
+     */
+    class ServiceInvalidAliasException : public ServiceException
+    {
+    public:
+      ServiceInvalidAliasException();
+      ServiceInvalidAliasException( const std::string & msg_r );
+      ServiceInvalidAliasException( const ServiceInfo & info );
+      ServiceInvalidAliasException( const ServiceInfo & info, const std::string & msg_r );
+    };
+
     /** Service already exists and some unique attribute can't be duplicated.
      */
     class ServiceAlreadyExistsException : public ServiceException