Imported Upstream version 15.0.0
[platform/upstream/libzypp.git] / zypp / url / UrlBase.cc
index b50bcbf..5238d52 100644 (file)
@@ -9,10 +9,10 @@
 /**
  * \file zypp/url/UrlBase.cc
  */
-#include <zypp/url/UrlBase.h>
-#include <zypp/base/String.h>
-#include <zypp/base/Gettext.h>
-#include <zypp/base/Regex.h>
+#include "zypp/url/UrlBase.h"
+#include "zypp/base/String.h"
+#include "zypp/base/Gettext.h"
+#include "zypp/base/Regex.h"
 
 #include <stdexcept>
 #include <climits>
 
 #include <iostream>
 
+// in the Estonian locale, a-z excludes t, for example. #302525
+// http://en.wikipedia.org/wiki/Estonian_alphabet
+#define a_zA_Z "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+
 // ---------------------------------------------------------------
 /*
 ** authority = //[user [:password] @ ] host [:port]
 **
 ** host      = hostname | IPv4 | "[" IPv6-IP "]" | "[v...]"
 */
-#define RX_VALID_SCHEME    "^[a-zA-Z][a-zA-Z0-9\\.+-]*$"
+#define RX_VALID_SCHEME    "^[" a_zA_Z "][" a_zA_Z "0-9\\.+-]*$"
 
 #define RX_VALID_PORT      "^[0-9]{1,5}$"
 
@@ -227,7 +231,11 @@ namespace zypp
                   const std::string &querystr,
                   const std::string &fragment)
     {
-      setScheme(scheme);
+      if ( scheme.empty() && *pathdata.c_str() == '/' )
+       setScheme("file");
+      else
+       setScheme(scheme);
+
       setAuthority(authority);
       setPathData(pathdata);
       setQueryString(querystr);
@@ -269,14 +277,14 @@ namespace zypp
       // n=no  (don't encode 2. slash if authority present)
       config("path_encode_slash2", "n");
 
-      config("rx_username",     "^([a-zA-Z0-9!$&'\\(\\)*+=,;~\\._-]|%[a-fA-F0-9]{2})+$");
-      config("rx_password",     "^([a-zA-Z0-9!$&'\\(\\)*+=,:;~\\._-]|%[a-fA-F0-9]{2})+$");
+      config("rx_username",     "^([" a_zA_Z "0-9!$&'\\(\\)*+=,;~\\._-]|%[a-fA-F0-9]{2})+$");
+      config("rx_password",     "^([" a_zA_Z "0-9!$&'\\(\\)*+=,:;~\\._-]|%[a-fA-F0-9]{2})+$");
 
-      config("rx_pathname",     "^([a-zA-Z0-9!$&'\\(\\)*+=,:@/~\\._-]|%[a-fA-F0-9]{2})+$");
-      config("rx_pathparams",   "^([a-zA-Z0-9!$&'\\(\\)*+=,:;@/~\\._-]|%[a-fA-F0-9]{2})+$");
+      config("rx_pathname",     "^([" a_zA_Z "0-9!$&'\\(\\)*+=,:@/~\\._-]|%[a-fA-F0-9]{2})+$");
+      config("rx_pathparams",   "^([" a_zA_Z "0-9!$&'\\(\\)*+=,:;@/~\\._-]|%[a-fA-F0-9]{2})+$");
 
-      config("rx_querystr",     "^([a-zA-Z0-9!$&'\\(\\)*+=,:;@/?~\\._-]|%[a-fA-F0-9]{2})+$");
-      config("rx_fragment",     "^([a-zA-Z0-9!$&'\\(\\)*+=,:;@/?~\\._-]|%[a-fA-F0-9]{2})+$");
+      config("rx_querystr",     "^([" a_zA_Z "0-9!$&'\\(\\)*+=,:;@/?~\\._-]|%[a-fA-F0-9]{2})+$");
+      config("rx_fragment",     "^([" a_zA_Z "0-9!$&'\\(\\)*+=,:;@/?~\\._-]|%[a-fA-F0-9]{2})+$");
     }
 
 
@@ -720,7 +728,7 @@ namespace zypp
           config("vsep_pathparam").empty())
       {
         ZYPP_THROW(UrlNotSupportedException(
-          _("Path parameter parsing not supported for this URL")
+          "Path parameter parsing not supported for this URL"
         ));
       }
       zypp::url::ParamMap pmap;
@@ -846,10 +854,8 @@ namespace zypp
           setUsername(s.substr(0, p), zypp::url::E_ENCODED);
         s = s.substr(p+1);
       }
-      q = s.rfind(']');
-      if ((p = s.rfind(':')) != std::string::npos && p > q+1)
+      if ((p = s.rfind(':')) != std::string::npos && ( (q = s.rfind(']')) == std::string::npos || q < p) )
       {
-
         setHost(s.substr(0, p));
         setPort(s.substr(p+1));
       }
@@ -1177,7 +1183,7 @@ namespace zypp
           config("vsep_pathparam").empty())
       {
         ZYPP_THROW(UrlNotSupportedException(
-          _("Path Parameter parsing not supported for this URL")
+          "Path Parameter parsing not supported for this URL"
         ));
       }
       setPathParams(
@@ -1244,6 +1250,15 @@ namespace zypp
           setQueryStringMap(pmap);
     }
 
+    // ---------------------------------------------------------------
+    void
+    UrlBase::delQueryParam(const std::string &param)
+    {
+          zypp::url::ParamMap pmap( getQueryStringMap(zypp::url::E_DECODED));
+          pmap.erase(param);
+          setQueryStringMap(pmap);
+    }
+
 
     // ---------------------------------------------------------------
     std::string
@@ -1316,7 +1331,7 @@ namespace zypp
         {
           struct in6_addr ip;
           std::string temp( host.substr(1, host.size()-2));
-          
+
           return inet_pton(AF_INET6, temp.c_str(), &ip) > 0;
         }
         else