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-codec.git
The following commit(s) were added to refs/heads/master by this push:
new 901b24ed RFC1522Codec.decodeText(String) now throws a DecoderException
instead of a StringIndexOutOfBoundsException when a separator is missing
901b24ed is described below
commit 901b24ed75867c5508a7baa6832451751719bf47
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Aug 6 11:28:45 2026 -0400
RFC1522Codec.decodeText(String) now throws a DecoderException instead of
a StringIndexOutOfBoundsException when a separator is missing
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/codec/net/RFC1522Codec.java | 2 +-
src/test/java/org/apache/commons/codec/net/BCodecTest.java | 5 +++++
src/test/java/org/apache/commons/codec/net/QCodecTest.java | 6 ++++++
4 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f4445b73..26a36f9e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
<release version="1.23.0" date="YYYY-MM-DD" description="This is a feature
and maintenance release. Java 8 or later is required.">
<!-- FIX -->
<action type="fix" dev="ggregory" due-to="Yu Bao, Gary Gregory">Optimize
PhoneticEngine.encode(String, LanguageSet) for speed.</action>
+ <action type="fix" dev="ggregory" due-to="Yu Bao, Gary
Gregory">RFC1522Codec.decodeText(String) now throws a DecoderException instead
of a StringIndexOutOfBoundsException when a separator is missing.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use
PhoneticEngine.Builder and deprecate old constructors.</action>
<!-- UPDATE -->
diff --git a/src/main/java/org/apache/commons/codec/net/RFC1522Codec.java
b/src/main/java/org/apache/commons/codec/net/RFC1522Codec.java
index 2b5380bb..538e60a1 100644
--- a/src/main/java/org/apache/commons/codec/net/RFC1522Codec.java
+++ b/src/main/java/org/apache/commons/codec/net/RFC1522Codec.java
@@ -81,7 +81,7 @@ abstract class RFC1522Codec {
final int terminator = text.length() - 2;
int from = 2;
int to = text.indexOf(SEP, from);
- if (to == terminator) {
+ if (to < 0 || to == terminator) {
throw new DecoderException("RFC 1522 violation: charset token not
found");
}
final String charset = text.substring(from, to);
diff --git a/src/test/java/org/apache/commons/codec/net/BCodecTest.java
b/src/test/java/org/apache/commons/codec/net/BCodecTest.java
index 94423192..1b85c1e1 100644
--- a/src/test/java/org/apache/commons/codec/net/BCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/BCodecTest.java
@@ -111,6 +111,11 @@ class BCodecTest {
assertThrows(DecoderException.class, () ->
bcodec.decode(Double.valueOf(3.0d)));
}
+ @Test
+ void testDecodeSeparatorNotFoundThrowsDecoderException() {
+ assertThrows(DecoderException.class, () -> new BCodec().decode("=?="));
+ }
+
@Test
void testDecodeStringWithNull() throws Exception {
final BCodec bcodec = new BCodec();
diff --git a/src/test/java/org/apache/commons/codec/net/QCodecTest.java
b/src/test/java/org/apache/commons/codec/net/QCodecTest.java
index 6ffa8e4a..95886e5e 100644
--- a/src/test/java/org/apache/commons/codec/net/QCodecTest.java
+++ b/src/test/java/org/apache/commons/codec/net/QCodecTest.java
@@ -70,6 +70,12 @@ class QCodecTest {
assertThrows(DecoderException.class, () ->
qcodec.decode(Double.valueOf(3.0d)), "Trying to url encode a Double object
should cause an exception.");
}
+ @Test
+ void testDecodeSeparatorNotFoundThrowsDecoderException() {
+ // QCodec
+ assertThrows(DecoderException.class, () -> new QCodec().decode("=?="));
+ }
+
@Test
void testDecodeStringWithNull() throws Exception {
final QCodec qcodec = new QCodec();