Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ private static void checkAddress(String addr,
"Local address ends with dot", addr);
break; // done with local part
}
if (c <= 040 || c == 0177)
if (c <= 040 || c >= 0177)
throw new AddressException(
"Local address contains control or whitespace", addr);
if (specialsNoDot.indexOf(c) >= 0)
Expand Down
26 changes: 26 additions & 0 deletions api/src/test/java/jakarta/mail/internet/InternetAddressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.util.Collection;
import java.util.List;

import static org.junit.Assert.assertThrows;

/**
* Test Internet address parsing.
*
Expand Down Expand Up @@ -379,4 +381,28 @@ private static final void pr(String s) {
private static final String n(String s) {
return s == null ? "<null>" : s;
}

@Test
public void testNonASCIICharacterValidation() {
// Test cases that should throw AddressException
String[] invalidAddresses = {
"testä[email protected]", // ä = 228
"të[email protected]", // ë = 235
"用户@example.com", // Chinese characters
"test@examplé.com" // é = 233
};

for (String addr : invalidAddresses) {
assertThrows(AddressException.class, () -> {
new InternetAddress(addr, true);
}, "Expected AddressException for strict constructor with address: " + addr);

assertThrows(AddressException.class, () -> {
InternetAddress address = new InternetAddress(addr);
address.validate();
}, "Expected AddressException for validate() with address: " + addr);
}
}


}