Skip to content

Commit

Permalink
Merge pull request #123 from lequal/dev
Browse files Browse the repository at this point in the history
Fix #122 : wrong url parsing
  • Loading branch information
Sancretor authored Mar 9, 2020
2 parents a81f4fc + 95549fd commit 7abf07a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.cnes.sonar</groupId>
<artifactId>cnesreport</artifactId>
<version>3.2.0</version>
<version>3.2.1</version>
<packaging>sonar-plugin</packaging>

<name>SonarQube CNES Report</name>
Expand Down
4 changes: 2 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sonar.projectKey=cnesreport
sonar.projectName=cnesreport
sonar.projectVersion=1.2.1
sonar.projectVersion=3.2.1
sonar.projectDescription=Export SonarQube report for a specific project.
sonar.sources=src/main
sonar.tests=src/test/ut
sonar.java.binaries=target/classes
sonar.java.binaries=target/classes
26 changes: 24 additions & 2 deletions src/main/java/fr/cnes/sonar/report/providers/RequestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public final class RequestManager {
*/
public static final String STR_PROXY_PASS = "https.proxyPassword";

public static final String QUERY_CHAR = "?";
public static final String ANCHOR_CHAR = "#";

/**
* Use of private constructor to singletonize this class
*/
Expand All @@ -73,6 +76,25 @@ public static synchronized RequestManager getInstance() {
return ourInstance;
}

/**
* Return the baseUrl from a string URL
* @return the baseUrl as string
*/
private static String extractBaseUrl(String url) {
if (url != null) {
int queryPosition = url.indexOf(QUERY_CHAR);
if (queryPosition <= 0) {
queryPosition = url.indexOf(ANCHOR_CHAR);
}

if (queryPosition >= 0) {
url = url.substring(0, queryPosition);
}
}

return StringUtils.substringBeforeLast(url, "/");
}

/**
* Execute a get http request
* @param url server to request
Expand All @@ -83,8 +105,8 @@ public static synchronized RequestManager getInstance() {
*/
public String get(final String url, final String token) throws SonarQubeException, BadSonarQubeRequestException {
// Initialize connexion information.
final String baseUrl = StringUtils.substringBeforeLast(url, "/");
final String path = StringUtils.substringAfterLast(url, "/");
final String baseUrl = extractBaseUrl(url);
final String path = url.replace(baseUrl, "");
final String proxyHost = System.getProperty(STR_PROXY_HOST, StringManager.EMPTY);
final String proxyPort = System.getProperty(STR_PROXY_PORT, StringManager.EMPTY);
final String proxyUser = System.getProperty(STR_PROXY_USER, StringManager.EMPTY);
Expand Down

0 comments on commit 7abf07a

Please sign in to comment.