-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from Recipe-Project/feature/fix_badwords_filter
Feature/fix badwords filter
- Loading branch information
Showing
24 changed files
with
126 additions
and
160 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/com/recipe/app/src/common/utils/BadWordFiltering.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.recipe.app.src.common.utils; | ||
|
||
import com.recipe.app.src.etc.exception.BadWordException; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.FileCopyUtils; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Component | ||
public class BadWordFiltering { | ||
|
||
private List<String> badWords; | ||
|
||
public BadWordFiltering() { | ||
|
||
try { | ||
|
||
ClassPathResource resource = new ClassPathResource("badwords.txt"); | ||
byte[] bdata = FileCopyUtils.copyToByteArray(resource.getInputStream()); | ||
String text = new String(bdata, StandardCharsets.UTF_8); | ||
|
||
this.badWords = Arrays.stream(text.replaceAll("\'", "").split(", ")).toList(); | ||
} catch (Exception e) { | ||
this.badWords = new ArrayList<>(); | ||
} | ||
} | ||
|
||
|
||
public void check(String keyword) { | ||
|
||
keyword = changeTextWithoutSpecialSymbols(keyword); | ||
|
||
for (String badWord : badWords) { | ||
if (keyword.contains(badWord)) { | ||
throw new BadWordException(badWord); | ||
} | ||
} | ||
} | ||
|
||
private String changeTextWithoutSpecialSymbols(String keyword) { | ||
return keyword.replaceAll("[^a-zA-Z0-9가-힣]", ""); | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
src/main/java/com/recipe/app/src/common/utils/ValidationRegex.java
This file was deleted.
Oops, something went wrong.
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
31 changes: 0 additions & 31 deletions
31
src/main/java/com/recipe/app/src/etc/application/BadWordService.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
src/main/java/com/recipe/app/src/etc/infra/BadWordRepository.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
...main/java/com/recipe/app/src/fridge/exception/FridgeSaveExpiredDateNotMatchException.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
src/main/java/com/recipe/app/src/fridge/exception/FridgeSaveUnitNotMatchException.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
...n/java/com/recipe/app/src/ingredient/exception/IngredientUsedInFridgeBasketException.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
src/main/java/com/recipe/app/src/ingredient/exception/IngredientUsedInFridgeException.java
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
src/main/java/com/recipe/app/src/ingredient/exception/IngredientUsedInRecipeException.java
This file was deleted.
Oops, something went wrong.
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
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
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
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
8 changes: 0 additions & 8 deletions
8
src/main/java/com/recipe/app/src/recipe/exception/NotFoundScrapException.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.