Skip to content

Commit

Permalink
bz-68462: Prevent StringIndexOutOfBoundsException when EmailAddress i…
Browse files Browse the repository at this point in the history
…s passed an empty String
  • Loading branch information
jaikiran committed Jan 11, 2024
1 parent c737d64 commit 36bfcaa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions WHATSNEW
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Fixed bugs:
command in the JDK supports the "--release" option.
Github Pull Request #205

* Fixes a bug in org.apache.tools.ant.taskdefs.email.EmailAddress which
would throw a java.lang.StringIndexOutOfBoundsException if the email
address passed to its constructor was an empty String.
Bugzilla Report 68462


Changes from Ant 1.10.13 TO Ant 1.10.14
=======================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ public EmailAddress(String email) {
* '(', ')', '"', '<', '>' from the start and end of strings
*/
private String trim(String t, boolean trimAngleBrackets) {
if (t.isEmpty()) {
return t;
}
int start = 0;
int end = t.length();
boolean trim;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ public void testD() {
expectNameAddress3(new EmailAddress(" < address > "));
}

/**
* verify that an empty value to EmailAddress constructor doesn't lead to
* a StringIndexOutOfBoundsException
*/
@Test
public void testEmpty() {
final EmailAddress addr = new EmailAddress("");
assertEquals("", addr.getName());
assertEquals("", addr.getAddress());
}

private void expectNameAddress(EmailAddress e) {
assertEquals("name", e.getName());
assertEquals("address", e.getAddress());
Expand Down

0 comments on commit 36bfcaa

Please sign in to comment.