This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git
The following commit(s) were added to refs/heads/master by this push:
new 249770ef Fix ArrayIndexOutOfBoundsException in DnsStringLookup for '|'
key (#765).
249770ef is described below
commit 249770ef6309e04c8bae84e5fa1dcd33bfaec803
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Aug 25 16:37:56 2026 -0400
Fix ArrayIndexOutOfBoundsException in DnsStringLookup for '|' key
(#765).
- Add action to changes.xml.
- Use longer lines.
- Sort members.
---
src/changes/changes.xml | 1 +
.../commons/text/lookup/DnsStringLookupTest.java | 29 +++++++++-------------
2 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 553da414..b9beac2e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -69,6 +69,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Javid Khan, Gary
Gregory">Return null for malformed input in UrlDecoderStringLookup
(#749).</action>
<action type="fix" dev="ggregory" issue="TEXT-241" due-to="Javid Khan,
Gary Gregory">TextStringBuilder.lastIndexOf("") and StrBuilder.lastIndexOf("")
return incorrect index for empty string (size - 1 instead of size)
(#763).</action>
<action type="fix" dev="ggregory" issue="TEXT-242" due-to="Maksym
Korshun">StringSubstitutorReader can now substitute variables with a suffix
longer than one characters (#764).</action>
+ <action type="fix" dev="ggregory" due-to="Javid Khan, Gary Gregory">Fix
ArrayIndexOutOfBoundsException in DnsStringLookup for '|' key (#765).</action>
<!-- ADD -->
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump
org.apache.commons:commons-parent from 93 to 104.</action>
diff --git
a/src/test/java/org/apache/commons/text/lookup/DnsStringLookupTest.java
b/src/test/java/org/apache/commons/text/lookup/DnsStringLookupTest.java
index a5c5f252..b0374771 100644
--- a/src/test/java/org/apache/commons/text/lookup/DnsStringLookupTest.java
+++ b/src/test/java/org/apache/commons/text/lookup/DnsStringLookupTest.java
@@ -35,29 +35,33 @@ class DnsStringLookupTest {
@Test
void testAddressFromHostAddress() throws UnknownHostException {
final InetAddress localHost = InetAddress.getLocalHost();
- assertEquals(localHost.getHostAddress(),
- DnsStringLookup.INSTANCE.apply("address|" +
localHost.getHostAddress()));
+ assertEquals(localHost.getHostAddress(),
DnsStringLookup.INSTANCE.apply("address|" + localHost.getHostAddress()));
}
@Test
void testAddressFromHostName() throws UnknownHostException {
final InetAddress localHost = InetAddress.getLocalHost();
- assertEquals(localHost.getHostAddress(),
- DnsStringLookup.INSTANCE.apply("address|" +
localHost.getHostName()));
+ assertEquals(localHost.getHostAddress(),
DnsStringLookup.INSTANCE.apply("address|" + localHost.getHostName()));
}
@Test
void testCanonicalNameFromHostAddress() throws UnknownHostException {
final InetAddress localHost = InetAddress.getLocalHost();
- assertEquals(localHost.getCanonicalHostName(),
- DnsStringLookup.INSTANCE.apply("canonical-name|" +
localHost.getHostAddress()));
+ assertEquals(localHost.getCanonicalHostName(),
DnsStringLookup.INSTANCE.apply("canonical-name|" + localHost.getHostAddress()));
}
@Test
void testCanonicalNameFromHostName() throws UnknownHostException {
final InetAddress localHost = InetAddress.getLocalHost();
- assertEquals(localHost.getCanonicalHostName(),
- DnsStringLookup.INSTANCE.apply("canonical-name|" +
localHost.getHostName()));
+ assertEquals(localHost.getCanonicalHostName(),
DnsStringLookup.INSTANCE.apply("canonical-name|" + localHost.getHostName()));
+ }
+
+ @Test
+ void testDelimiterOnlyKey() {
+ // A key that is only delimiter/whitespace splits to an empty array;
must not throw.
+ assertNull(DnsStringLookup.INSTANCE.apply("|"));
+ assertNull(DnsStringLookup.INSTANCE.apply("||"));
+ assertNull(DnsStringLookup.INSTANCE.apply(" | "));
}
@Test
@@ -73,14 +77,6 @@ class DnsStringLookupTest {
assertTrue(matched);
}
- @Test
- void testDelimiterOnlyKey() {
- // A key that is only delimiter/whitespace splits to an empty array;
must not throw.
- assertNull(DnsStringLookup.INSTANCE.apply("|"));
- assertNull(DnsStringLookup.INSTANCE.apply("||"));
- assertNull(DnsStringLookup.INSTANCE.apply(" | "));
- }
-
@Test
void testNull() {
assertNull(DnsStringLookup.INSTANCE.apply(null));
@@ -91,5 +87,4 @@ class DnsStringLookupTest {
// does not blow up and gives some kind of string.
assertFalse(DnsStringLookup.INSTANCE.toString().isEmpty());
}
-
}