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-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 54ee8ec1c Reject non-ASCII hex characters in Conversion.hexDigitToInt
(#1767)
54ee8ec1c is described below
commit 54ee8ec1c9c44a6617e8e41acf475a79857ac564
Author: alhuda <[email protected]>
AuthorDate: Tue Aug 4 17:02:18 2026 +0530
Reject non-ASCII hex characters in Conversion.hexDigitToInt (#1767)
---
src/main/java/org/apache/commons/lang3/Conversion.java | 5 ++---
src/test/java/org/apache/commons/lang3/ConversionTest.java | 6 ++++++
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/Conversion.java
b/src/main/java/org/apache/commons/lang3/Conversion.java
index f9041ba0d..a128768c2 100644
--- a/src/main/java/org/apache/commons/lang3/Conversion.java
+++ b/src/main/java/org/apache/commons/lang3/Conversion.java
@@ -727,11 +727,10 @@ public static boolean[] hexDigitToBinary(final char
hexChar) {
* @throws IllegalArgumentException if {@code hexDigit} is not a
hexadecimal digit.
*/
public static int hexDigitToInt(final char hexChar) {
- final int digit = Character.digit(hexChar, 16);
- if (digit < 0) {
+ if (!CharUtils.isHex(hexChar)) {
throw new IllegalArgumentException("Cannot convert '" + hexChar +
"' to a hexadecimal digit");
}
- return digit;
+ return Character.digit(hexChar, 16);
}
/**
diff --git a/src/test/java/org/apache/commons/lang3/ConversionTest.java
b/src/test/java/org/apache/commons/lang3/ConversionTest.java
index 784ba3235..67828318f 100644
--- a/src/test/java/org/apache/commons/lang3/ConversionTest.java
+++ b/src/test/java/org/apache/commons/lang3/ConversionTest.java
@@ -688,6 +688,11 @@ void testHexDigitToInt() {
assertEquals(15, Conversion.hexDigitToInt('F'));
assertEquals(15, Conversion.hexDigitToInt('f'));
assertIllegalArgumentException(() -> Conversion.hexDigitToInt('G'));
+ assertIllegalArgumentException(() ->
Conversion.hexDigitToInt('\uFF41')); // FULLWIDTH LATIN SMALL LETTER A
+ assertIllegalArgumentException(() ->
Conversion.hexDigitToInt('\uFF26')); // FULLWIDTH LATIN CAPITAL LETTER F
+ assertIllegalArgumentException(() ->
Conversion.hexDigitToInt('\uFF19')); // FULLWIDTH DIGIT NINE
+ assertIllegalArgumentException(() ->
Conversion.hexDigitToInt('\u0669')); // ARABIC-INDIC DIGIT NINE
+ assertIllegalArgumentException(() ->
Conversion.hexDigitToInt('\u096B')); // DEVANAGARI DIGIT FIVE
}
/**
@@ -723,6 +728,7 @@ void testHexToInt() {
assertThrows(StringIndexOutOfBoundsException.class, () ->
Conversion.hexToInt(src, Integer.MIN_VALUE, 0, 0, 1));
assertThrows(StringIndexOutOfBoundsException.class, () ->
Conversion.hexToInt(src, Integer.MAX_VALUE, 0, 0, 1));
assertIllegalArgumentException(() -> Conversion.hexToInt(src,
Integer.MAX_VALUE, 0, 0, Integer.SIZE));
+ assertIllegalArgumentException(() ->
Conversion.hexToInt("\uFF41\uFF41", 0, 0, 0, 2));
}
/**