Skip to content

Commit

Permalink
Do not use httpclient URIUtil.encodePath()
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek committed Nov 8, 2017
1 parent 73a9b2b commit e75532a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
58 changes: 58 additions & 0 deletions src/main/java/com/cloudbees/jenkins/plugins/bitbucket/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* The MIT License
*
* Copyright (c) 2016-2017, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.cloudbees.jenkins.plugins.bitbucket;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Util;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;


/**
* Utility functions
*/
@Restricted(NoExternalUse.class)
public class Utils {

/**
* URL encodes each path segment
* @param path path separated by '/'
* @return encoded path separated by '/'
*/
public static @NonNull String encodePath(@NonNull String path){
StringBuilder sb = new StringBuilder();
boolean first = true;
for (String segment : StringUtils.split(path, "/")) {
sb.append(Util.rawEncode(segment));
if (first) {
first = false;
} else {
sb.append('/');
}
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.type.TypeReference;
import static org.apache.commons.httpclient.util.URIUtil.encodePath;
import static com.cloudbees.jenkins.plugins.bitbucket.Utils.encodePath;

public class BitbucketCloudApiClient implements BitbucketApi {
private static final Logger LOGGER = Logger.getLogger(BitbucketCloudApiClient.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.type.TypeReference;
import static org.apache.commons.httpclient.util.URIUtil.encodePath;
import static com.cloudbees.jenkins.plugins.bitbucket.Utils.encodePath;

/**
* Bitbucket API client.
Expand Down Expand Up @@ -741,4 +741,5 @@ private Map<String,Object> collectLines(String response, final List<String> line
}
return content;
}

}

0 comments on commit e75532a

Please sign in to comment.