Skip to content

Commit

Permalink
fix: Fix for #125 caused by pattern also allowing empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
en-milie committed May 30, 2024
1 parent 408c889 commit 1f936a9
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public class StringGenerator {
public static final String ALPHANUMERIC = "[a-zA-Z0-9]";

private static final int MAX_ATTEMPTS_GENERATE = 5;

private static final String ALPHANUMERIC_VALUE = "CatsIsCool";

private static final String EMPTY_PATTERN = "(\\^\\$\\|)|(\\|\\^\\$)|(\\^\\$)";

/**
* Represents an empty string.
*/
Expand Down Expand Up @@ -174,6 +179,7 @@ public static String cleanPattern(String pattern) {
if (pattern.endsWith("$/")) {
pattern = StringUtils.removeEnd(pattern, "/");
}
pattern = pattern.replaceAll(EMPTY_PATTERN, EMPTY);
return pattern;
}

Expand Down Expand Up @@ -223,7 +229,7 @@ private static String generateUsingRgxGenerator(String pattern, int min, int max
} while (attempts < MAX_ATTEMPTS_GENERATE && !generatedValue.matches(pattern));
} catch (Exception e) {
LOGGER.debug("RGX generator failed, returning empty.", e);
return EMPTY;
return ALPHANUMERIC_VALUE;
}
LOGGER.debug("Generated using RGX {}", generatedValue);
return generatedValue;
Expand Down

0 comments on commit 1f936a9

Please sign in to comment.