Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple separators in the 'No proxy host' field: pipe (|), semicolon (;), newline, and comma (,) #108

Merged
merged 12 commits into from
Oct 7, 2024
Merged
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[]{";;;", ""},
Nathan770 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading