File tree Expand file tree Collapse file tree 4 files changed +12
-3
lines changed
Expand file tree Collapse file tree 4 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ public static String parse(String query) {
2929 if (!StringUtils .hasText (query )) {
3030 throw new InvalidInputException ("Full text query parameter has @NotNull @NotBlank requirement" );
3131 }
32- String parsedQuery = Stream .of (query .split ("[ @.,+*]" ))
32+ String parsedQuery = Stream .of (query .split ("[ @.,+*- ]" ))
3333 .filter (part -> !(part .isEmpty () || stopWords .contains (part .toLowerCase ())))
3434 .map (part -> "+" + part )
3535 .collect (Collectors .joining (" " ));
Original file line number Diff line number Diff line change 11package invite .validation ;
22
3+ import org .springframework .util .StringUtils ;
4+
35import java .util .regex .Pattern ;
46
57public class EmailFormatValidator implements FormatValidator {
@@ -9,9 +11,12 @@ public class EmailFormatValidator implements FormatValidator {
911
1012 @ Override
1113 public boolean isValid (String subject ) {
12- return pattern .matcher (subject ).matches ();
14+ return StringUtils . hasText ( subject ) && ! hasMoreThanOneAt ( subject ) && pattern .matcher (subject ).matches ();
1315 }
1416
17+ private boolean hasMoreThanOneAt (String input ) {
18+ return input .indexOf ('@' ) != -1 && input .indexOf ('@' ) != input .lastIndexOf ('@' );
19+ }
1520 @ Override
1621 public String formatName () {
1722 return "email" ;
Original file line number Diff line number Diff line change @@ -18,6 +18,9 @@ void parse() {
1818
1919 String strippedWhiteSpace = FullSearchQueryParser .parse (" Leitndhireedisvea@example.com " );
2020 assertEquals ("+Leitndhireedisvea +example*" , strippedWhiteSpace );
21+
22+ String minusCharacter = FullSearchQueryParser .parse ("role-bug" );
23+ assertEquals ("+role +bug*" , minusCharacter );
2124 }
2225
2326 @ Test
Original file line number Diff line number Diff line change 22
33import org .junit .jupiter .api .Test ;
44
5+ import static org .junit .jupiter .api .Assertions .assertFalse ;
56import static org .junit .jupiter .api .Assertions .assertTrue ;
67
78class EmailFormatValidatorTest {
@@ -12,6 +13,6 @@ class EmailFormatValidatorTest {
1213 void isValid () {
1314 assertTrue (emailFormatValidator .isValid ("o@o" ));
1415 assertTrue (emailFormatValidator .isValid ("Frits Voorbeeld <frits.fritsmans@voorbeeld.nl>" ));
15-
16+ assertFalse ( emailFormatValidator . isValid ( "o@@o" ));
1617 }
1718}
You can’t perform that action at this time.
0 commit comments