mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-03 04:12:31 +01:00 
			
		
		
		
	Cleanup in UriUtils.getUpdateUri
- String instantiation replaced with StringBuilder and empty string constant Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
This commit is contained in:
		
							parent
							
								
									59364ee9a4
								
							
						
					
					
						commit
						351ccf3755
					
				@ -143,7 +143,7 @@ public class UriUtils {
 | 
			
		||||
            URIBuilder builder = new URIBuilder(url);
 | 
			
		||||
            builder.removeQuery();
 | 
			
		||||
 | 
			
		||||
            String updatedQuery = new String();
 | 
			
		||||
            StringBuilder updatedQuery = new StringBuilder();
 | 
			
		||||
            List<NameValuePair> queryParams = getUserDetails(query);
 | 
			
		||||
            ListIterator<NameValuePair> iterator = queryParams.listIterator();
 | 
			
		||||
            while (iterator.hasNext()) {
 | 
			
		||||
@ -156,14 +156,16 @@ public class UriUtils {
 | 
			
		||||
                    value = param.getValue();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (updatedQuery.isEmpty()) {
 | 
			
		||||
                    updatedQuery += (param.getName() + "=" + value);
 | 
			
		||||
                if (updatedQuery.length() == 0) {
 | 
			
		||||
                    updatedQuery.append(param.getName()).append('=')
 | 
			
		||||
                            .append(value);
 | 
			
		||||
                } else {
 | 
			
		||||
                    updatedQuery += ("&" + param.getName() + "=" + value);
 | 
			
		||||
                    updatedQuery.append('&').append(param.getName())
 | 
			
		||||
                            .append('=').append(value);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            String schemeAndHost = new String();
 | 
			
		||||
            String schemeAndHost = "";
 | 
			
		||||
            URI newUri = builder.build();
 | 
			
		||||
            if (newUri.getScheme() != null) {
 | 
			
		||||
                schemeAndHost = newUri.getScheme() + "://" + newUri.getHost();
 | 
			
		||||
 | 
			
		||||
@ -47,6 +47,10 @@ public class UriUtilsTest {
 | 
			
		||||
                "http://localhost/foo/bar?password=1234", true).startsWith(
 | 
			
		||||
                "http://localhost/foo/bar"));
 | 
			
		||||
 | 
			
		||||
        //just to see if it is still ok with multiple parameters
 | 
			
		||||
        Assert.assertEquals("http://localhost/foo/bar?param1=true¶m2=12345", UriUtils
 | 
			
		||||
                .getUpdateUri("http://localhost/foo/bar?param1=true¶m2=12345", false));
 | 
			
		||||
 | 
			
		||||
        //XXX: Interesting cases not covered:
 | 
			
		||||
        // * port is ignored and left out from the return value
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user