Skip to content

Commit 36bfcaa

Browse files
committed
bz-68462: Prevent StringIndexOutOfBoundsException when EmailAddress is passed an empty String
1 parent c737d64 commit 36bfcaa

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

WHATSNEW

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ Fixed bugs:
3131
command in the JDK supports the "--release" option.
3232
Github Pull Request #205
3333

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

3540
Changes from Ant 1.10.13 TO Ant 1.10.14
3641
=======================================

src/main/org/apache/tools/ant/taskdefs/email/EmailAddress.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public EmailAddress(String email) {
117117
* '(', ')', '"', '<', '>' from the start and end of strings
118118
*/
119119
private String trim(String t, boolean trimAngleBrackets) {
120+
if (t.isEmpty()) {
121+
return t;
122+
}
120123
int start = 0;
121124
int end = t.length();
122125
boolean trim;

src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ public void testD() {
9393
expectNameAddress3(new EmailAddress(" < address > "));
9494
}
9595

96+
/**
97+
* verify that an empty value to EmailAddress constructor doesn't lead to
98+
* a StringIndexOutOfBoundsException
99+
*/
100+
@Test
101+
public void testEmpty() {
102+
final EmailAddress addr = new EmailAddress("");
103+
assertEquals("", addr.getName());
104+
assertEquals("", addr.getAddress());
105+
}
106+
96107
private void expectNameAddress(EmailAddress e) {
97108
assertEquals("name", e.getName());
98109
assertEquals("address", e.getAddress());

0 commit comments

Comments
 (0)