-
-
Save atomfrede/311f8a9c6eb74c5c5226af0481155207 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testLogins() { | |
Pattern compile = Pattern.compile(Constants.LOGIN_REGEX); | |
assertThat(compile.matcher("").matches()).isFalse(); | |
assertThat(compile.matcher("aaaaaaaa@").matches()).isFalse(); | |
assertThat(compile.matcher("admin").matches()).isTrue(); | |
assertThat(compile.matcher("aaaaaaaa@1").matches()).isTrue(); | |
assertThat(compile.matcher("me@example.com").matches()).isTrue(); | |
assertThat(compile.matcher("me@example.top.com").matches()).isTrue(); | |
assertThat(compile.matcher("me+foo@example.top.com").matches()).isTrue(); | |
// Works | |
StringBuilder sb1 = new StringBuilder(); | |
IntStream.range(0, 30000) | |
.forEach(it -> sb1.append("a")); | |
sb1.append("@1"); | |
assertThat(compile.matcher(sb1.toString()).matches()).isTrue(); | |
// Very bad | |
StringBuilder sb = new StringBuilder(); | |
IntStream.range(0, 30000) | |
.forEach(it -> sb.append("a")); | |
sb.append("@"); | |
assertThat(compile.matcher(sb.toString()).matches()).isFalse(); | |
} |
Author
atomfrede
commented
May 7, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment