This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-validator.git


The following commit(s) were added to refs/heads/master by this push:
     new 2273e99c Add check that pattern agrees with length
2273e99c is described below

commit 2273e99cefae2839c1da157ed1aeb0489ab8e5c5
Author: Sebb <s...@apache.org>
AuthorDate: Fri Jan 3 15:10:28 2025 +0000

    Add check that pattern agrees with length
---
 .../org/apache/commons/validator/routines/IBANValidatorTest.java   | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java 
b/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java
index 8a87654a..168dd3db 100644
--- a/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java
@@ -228,19 +228,21 @@ public class IBANValidatorTest {
     );
     // @formatter:on
 
-    private static String fmtRE(final String ibanPat) {
+    private static String fmtRE(final String ibanPat, final int ibanLength) {
         final Matcher m = IBAN_PAT.matcher(ibanPat);
         if (!m.matches()) {
             throw new IllegalArgumentException("Unexpected IBAN pattern " + 
ibanPat);
         }
         final StringBuilder sb = new StringBuilder();
         int len = Integer.parseInt(m.group(1)); // length of part
+        int totLen = len;
         String curType = m.group(2); // part type
         for (int i = 3; i <= m.groupCount(); i += 2) {
             if (m.group(i) == null) { // reached an optional group
                 break;
             }
             final int count = Integer.parseInt(m.group(i));
+            totLen += count;
             final String type = m.group(i + 1);
             if (type.equals(curType)) { // more of the same type
                 len += count;
@@ -251,6 +253,7 @@ public class IBANValidatorTest {
             }
         }
         sb.append(formatToRE(curType, len));
+        assertEquals(ibanLength, totLen, "Wrong length for " + ibanPat);
         return sb.toString();
     }
 
@@ -514,7 +517,7 @@ public class IBANValidatorTest {
 
         final List<String> allPatterns = 
Arrays.stream(validator.getRegexValidator().getPatterns()).map(Pattern::pattern).collect(Collectors.toList());
 
-        final String re = fmtRE(structure.substring(2));
+        final String re = fmtRE(structure.substring(2), ibanLength - 2); 
//allow for prefix
         assertTrue(allPatterns.remove(countryCode + re), "No pattern " + 
countryCode + re + " found for " + countryInfo);
         for (final String ac : acountyCode) {
             assertTrue(allPatterns.remove(ac + re), "No additional country 
code " + ac + " found for " + countryInfo);

Reply via email to