diff --git a/src/main/java/org/owasp/esapi/EncoderConstants.java b/src/main/java/org/owasp/esapi/EncoderConstants.java index ec2cbfac4..d9231528a 100644 --- a/src/main/java/org/owasp/esapi/EncoderConstants.java +++ b/src/main/java/org/owasp/esapi/EncoderConstants.java @@ -21,12 +21,12 @@ public class EncoderConstants { } /** - * a-b + * a-z */ public final static char[] CHAR_LOWERS = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; public final static Set LOWERS; static { - LOWERS = CollectionsUtil.arrayToSet(CHAR_PASSWORD_SPECIALS); + LOWERS = CollectionsUtil.arrayToSet(CHAR_LOWERS); } /** @@ -81,7 +81,7 @@ public class EncoderConstants { public final static char[] CHAR_PASSWORD_LOWERS = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; public final static Set PASSWORD_LOWERS; static { - PASSWORD_LOWERS = CollectionsUtil.arrayToSet(CHAR_ALPHANUMERICS); + PASSWORD_LOWERS = CollectionsUtil.arrayToSet(CHAR_PASSWORD_LOWERS); } /** diff --git a/src/test/java/org/owasp/esapi/EncoderConstantsTest.java b/src/test/java/org/owasp/esapi/EncoderConstantsTest.java new file mode 100644 index 000000000..761a44c36 --- /dev/null +++ b/src/test/java/org/owasp/esapi/EncoderConstantsTest.java @@ -0,0 +1,54 @@ +/** + * OWASP Enterprise Security API (ESAPI) + * + * This file is part of the Open Web Application Security Project (OWASP) + * Enterprise Security API (ESAPI) project. For details, please see + * http://www.owasp.org/index.php/ESAPI. + * + * Copyright (c) 2026 - The OWASP Foundation + * + * The ESAPI is published by OWASP under the BSD license. You should read and accept the + * LICENSE before you use, modify, and/or redistribute this software. + */ +package org.owasp.esapi; + +import static org.junit.Assert.assertEquals; + +import java.util.Set; + +import org.junit.Test; +import org.owasp.esapi.util.CollectionsUtil; + +/** + * Each {@code Set} in {@link EncoderConstants} should hold exactly + * the characters of its matching {@code CHAR_*} array. + */ +public class EncoderConstantsTest { + + private static void assertSameChars(char[] expected, Set actual) { + assertEquals(CollectionsUtil.arrayToSet(expected), actual); + } + + @Test + public void testLowers() { + assertSameChars(EncoderConstants.CHAR_LOWERS, EncoderConstants.LOWERS); + } + + @Test + public void testPasswordLowers() { + assertSameChars(EncoderConstants.CHAR_PASSWORD_LOWERS, EncoderConstants.PASSWORD_LOWERS); + } + + @Test + public void testOtherSetsMatchTheirArrays() { + assertSameChars(EncoderConstants.CHAR_PASSWORD_SPECIALS, EncoderConstants.PASSWORD_SPECIALS); + assertSameChars(EncoderConstants.CHAR_UPPERS, EncoderConstants.UPPERS); + assertSameChars(EncoderConstants.CHAR_DIGITS, EncoderConstants.DIGITS); + assertSameChars(EncoderConstants.CHAR_SPECIALS, EncoderConstants.SPECIALS); + assertSameChars(EncoderConstants.CHAR_LETTERS, EncoderConstants.LETTERS); + assertSameChars(EncoderConstants.CHAR_ALPHANUMERICS, EncoderConstants.ALPHANUMERICS); + assertSameChars(EncoderConstants.CHAR_PASSWORD_UPPERS, EncoderConstants.PASSWORD_UPPERS); + assertSameChars(EncoderConstants.CHAR_PASSWORD_DIGITS, EncoderConstants.PASSWORD_DIGITS); + assertSameChars(EncoderConstants.CHAR_PASSWORD_LETTERS, EncoderConstants.PASSWORD_LETTERS); + } +}