Skip to content

Commit

Permalink
Support for multiple separators in the 'No proxy host' field: pipe (|…
Browse files Browse the repository at this point in the history
…), semicolon (;), newline, and comma (,) (#108)
  • Loading branch information
Nathan770 authored Oct 7, 2024
1 parent 74fe389 commit 2806cda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/main/java/io/jenkins/plugins/jfrog/CliEnvConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ private static void excludeProxyEnvFromPublishing(EnvVars env) {
}

/**
* Converts a list of No Proxy Hosts received by Jenkins into a semicolon-separated string format expected by JFrog CLI.
* Converts a list of No Proxy Hosts received by Jenkins into a comma-separated string format expected by JFrog CLI.
*
* @param noProxy - A string representing the list of No Proxy Hosts.
* @return A semicolon-separated string of No Proxy Hosts.
* @return A comma-separated string of No Proxy Hosts.
*/
static String createNoProxyValue(String noProxy) {
// Trim leading and trailing spaces, Replace '|' with spaces and normalize whitespace
String noProxyListRemoveSpaceAndPipe = noProxy.trim().replaceAll("[\\s|]+", ";");
// Replace multiple semicolon with a single semicolon, and remove the last one if present
return noProxyListRemoveSpaceAndPipe.replaceAll(";+", ";").replaceAll("^;|;$", "");
// Trim leading and trailing spaces, Replace '|' and ';' with spaces and normalize whitespace
String noProxyListRemoveSpaceAndPipe = noProxy.trim().replaceAll("[\\s|;]+", ",");
// Replace multiple commas with a single comma, and remove the last one if present
return noProxyListRemoveSpaceAndPipe.replaceAll(",+", ",").replaceAll("^,|,$", "");
}
}
17 changes: 10 additions & 7 deletions src/test/java/io/jenkins/plugins/jfrog/CreateNoProxyValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ public CreateNoProxyValueTest(String noProxy, String expectedResult) {
public static Collection<Object[]> dataProvider() {
return Arrays.asList(
new Object[]{"artifactory.jfrog.io", "artifactory.jfrog.io"},
new Object[]{"artifactory.jfrog.io \n artifactory1.jfrog.io ", "artifactory.jfrog.io;artifactory1.jfrog.io"},
new Object[]{" artifactory.jfrog.io \n \r artifactory1.jfrog.io;artifactory2.jfrog.io \n artifactory3.jfrog.io | artifactory4.jfrog.io \n artifactory5.jfrog.io ", "artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io;artifactory4.jfrog.io;artifactory5.jfrog.io"},
new Object[]{"artifactory.jfrog.io \n artifactory1.jfrog.io ", "artifactory.jfrog.io,artifactory1.jfrog.io"},
new Object[]{" artifactory.jfrog.io \n \r artifactory1.jfrog.io;artifactory2.jfrog.io \n artifactory3.jfrog.io | artifactory4.jfrog.io \n artifactory5.jfrog.io ", "artifactory.jfrog.io,artifactory1.jfrog.io,artifactory2.jfrog.io,artifactory3.jfrog.io,artifactory4.jfrog.io,artifactory5.jfrog.io"},
new Object[]{"\r\n", ""},
new Object[]{";;;", ""},
new Object[]{",,,", ""},
new Object[]{"artifactory.jfrog.io;", "artifactory.jfrog.io"},
new Object[]{"artifactory.jfrog.io;artifactory1.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io"},
new Object[]{"artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io"},
new Object[]{"artifactory.jfrog.io \nartifactory1.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io"},
new Object[]{"artifactory.jfrog.io \nartifactory1.jfrog.io\nartifactory2.jfrog.io \n artifactory3.jfrog.io", "artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io"},
new Object[]{";artifactory.jfrog.io;", "artifactory.jfrog.io"}
new Object[]{"artifactory.jfrog.io,artifactory1.jfrog.io", "artifactory.jfrog.io,artifactory1.jfrog.io"},
new Object[]{"artifactory.jfrog.io;artifactory1.jfrog.io;artifactory2.jfrog.io;artifactory3.jfrog.io", "artifactory.jfrog.io,artifactory1.jfrog.io,artifactory2.jfrog.io,artifactory3.jfrog.io"},
new Object[]{"artifactory.jfrog.io|artifactory1.jfrog.io|artifactory2.jfrog.io|artifactory3.jfrog.io", "artifactory.jfrog.io,artifactory1.jfrog.io,artifactory2.jfrog.io,artifactory3.jfrog.io"},
new Object[]{"artifactory.jfrog.io\nartifactory1.jfrog.io", "artifactory.jfrog.io,artifactory1.jfrog.io"},
new Object[]{"artifactory.jfrog.io \nartifactory1.jfrog.io\nartifactory2.jfrog.io \n artifactory3.jfrog.io", "artifactory.jfrog.io,artifactory1.jfrog.io,artifactory2.jfrog.io,artifactory3.jfrog.io"},
new Object[]{";artifactory.jfrog.io;", "artifactory.jfrog.io"},
new Object[]{",artifactory.jfrog.io,", "artifactory.jfrog.io"}
);
}

Expand Down

0 comments on commit 2806cda

Please sign in to comment.