Skip to content

Commit

Permalink
fix: Fix for #128 for case insensitive regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
en-milie committed Jun 4, 2024
1 parent 1249fbf commit 7814815
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class StringGenerator {
private static final org.cornutum.regexpgen.Provider REGEXPGEN_PROVIDER = Provider.forEcmaScript();

private static final PrettyLogger LOGGER = PrettyLoggerFactory.getLogger(StringGenerator.class);
public static final String CASE_INSENSITIVE = "\\(\\?i\\)";

private StringGenerator() {
//ntd
Expand Down Expand Up @@ -180,6 +181,7 @@ public static String cleanPattern(String pattern) {
pattern = StringUtils.removeEnd(pattern, "/");
}
pattern = pattern.replaceAll(EMPTY_PATTERN, EMPTY);
pattern = pattern.replaceAll(CASE_INSENSITIVE, EMPTY);
return pattern;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,10 @@ void shouldGenerateWhenOrEmpty() {
String generated = StringGenerator.generate("^$|^(?i)(http:\\/\\/|https:\\/\\/)([a-z0-9./\\-_.~+=:;%&?]+)$", 100, 100);
Assertions.assertThat(generated).hasSize(100).matches("^(?i)(http://|https://)([a-z0-9./\\-_.~+=:;%&?]+)");
}

@Test
void shouldRemoveCaseInsensitive() {
String generated = StringGenerator.cleanPattern("^(?i)(http:\\/\\/|https:\\/\\/)([a-z0-9./\\-_.~+=:;%&?]+)$");
Assertions.assertThat(generated).isEqualTo("^(http:\\/\\/|https:\\/\\/)([a-z0-9./\\-_.~+=:;%&?]+)$");
}
}

0 comments on commit 7814815

Please sign in to comment.