Skip to content

Commit

Permalink
Merge pull request #95 from aheritier/JENKINS-64854
Browse files Browse the repository at this point in the history
[JENKINS-64854] Fix encoding for emails in CC
  • Loading branch information
aheritier authored Mar 9, 2021
2 parents 12682a4 + 7c7b558 commit e511443
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import hudson.Util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.logging.Logger;

public final class EmailUtil {

private static final Logger LOG = Logger.getLogger(EmailUtil.class.getName());

private EmailUtil() {
throw new UnsupportedOperationException("Cannot instantiate utility class");
}
Expand All @@ -17,9 +23,15 @@ public static String fixEmptyAndTrimAllSpaces(String value) {
}

public static String urlEncode(String value) {
if (value != null) {
value = value.replaceAll(",", "%2C");
if (value == null) {
return null;
}
try {
return URLEncoder.encode(value, "UTF-8");
} catch (UnsupportedEncodingException unsupportedEncodingException) {
LOG.warning(
"UTF-8 is not supported to encode the URL parameter " + value + " : " + unsupportedEncodingException.getMessage());
return value;
}
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public void fixEmptyAndTrimAllSpaces() {

@Test
public void urlEncode() {
assertThat(EmailUtil.urlEncode(EMAIL), is(EMAIL));
assertThat(EmailUtil.urlEncode(EMAIL + "," + EMAIL), is(EMAIL + "%2C" + EMAIL));
assertThat(EmailUtil.urlEncode(EMAIL), is("test%40acme.com"));
assertThat(EmailUtil.urlEncode("test+foo@acme.com"), is("test%2Bfoo%40acme.com"));
assertThat(EmailUtil.urlEncode(EMAIL + "," + EMAIL), is("test%40acme.com%2Ctest%40acme.com"));
assertThat(EmailUtil.urlEncode(null), is(nullValue()));
}

Expand Down

0 comments on commit e511443

Please sign in to comment.