@@ -619,21 +619,30 @@ public static UriInfo getUriInfo(String url) {
619619 }
620620
621621 private static UriInfo getRbdUrlInfo (String url ) {
622- int secondSlash = StringUtils .ordinalIndexOf (url , "/" , 2 );
623- int thirdSlash = StringUtils .ordinalIndexOf (url , "/" , 3 );
622+ if (url == null || !url .toLowerCase ().startsWith ("rbd://" )) {
623+ throw new CloudRuntimeException ("RBD URL must start with \" rbd://\" " );
624+ }
625+ String schema = StringUtils .substring (url , 0 , 6 );
626+ url = StringUtils .substring (url , 6 , url .length ());
624627 int firstAt = StringUtils .indexOf (url , "@" );
625- int lastColon = StringUtils .lastIndexOf (url ,":" );
626- int lastSquareBracket = StringUtils .lastIndexOf (url ,"]" );
627- int startOfHost = Math .max (secondSlash , firstAt ) + 1 ;
628- int endOfHost = lastColon < startOfHost ? (thirdSlash > 0 ? thirdSlash : url .length () + 1 ) :
628+ String credentials = (firstAt == -1 ) ? null : StringUtils .substring (url , 0 , firstAt );
629+ String hostInfo = (firstAt == -1 ) ? url : StringUtils .substring (url , firstAt + 1 , url .length ());
630+
631+ int firstSlash = StringUtils .indexOf (hostInfo , "/" );
632+ int lastColon = StringUtils .lastIndexOf (hostInfo ,":" );
633+ int lastSquareBracket = StringUtils .lastIndexOf (hostInfo ,"]" );
634+ int endOfHost = lastColon == -1 ? (firstSlash > 0 ? firstSlash : hostInfo .length () + 1 ) :
629635 (lastSquareBracket > lastColon ? lastSquareBracket + 1 : lastColon );
630- String storageHosts = StringUtils .substring (url , startOfHost , endOfHost );
636+ String storageHosts = StringUtils .substring (hostInfo , 0 , endOfHost );
631637 String firstHost = storageHosts .split ("," )[0 ];
632- String strBeforeHosts = StringUtils .substring (url , 0 , startOfHost );
633- String strAfterHosts = StringUtils .substring (url , endOfHost );
638+ String strAfterHosts = StringUtils .substring (hostInfo , endOfHost );
634639 try {
635- URI uri = new URI (UriUtils .encodeURIComponent (strBeforeHosts + firstHost + strAfterHosts ));
636- return new UriInfo (uri .getScheme (), storageHosts , uri .getPath (), uri .getUserInfo (), uri .getPort ());
640+ URI uri = new URI (UriUtils .encodeURIComponent (schema + firstHost + strAfterHosts ));
641+ if (credentials != null ) {
642+ credentials = credentials .replace ("+" , "-" );
643+ credentials = credentials .replace ("/" , "_" );
644+ }
645+ return new UriInfo (uri .getScheme (), storageHosts , uri .getPath (), credentials , uri .getPort ());
637646 } catch (URISyntaxException e ) {
638647 throw new CloudRuntimeException (url + " is not a valid uri for RBD" );
639648 }
0 commit comments