Skip to content

Commit

Permalink
Merge pull request #12 from Blaspsoft/blasp-refactor
Browse files Browse the repository at this point in the history
regex tweaks and bug fixes
  • Loading branch information
deemonic authored Nov 27, 2024
2 parents d8dc4d8 + d41e00e commit ec96e3e
Show file tree
Hide file tree
Showing 8 changed files with 1,393 additions and 238 deletions.
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ use Blaspsoft\Blasp\Facades\Blasp;
$sentence = 'This is a fucking shit sentence';
$check = Blasp::check($sentence);
```
you can also change the default language to french
```php
use Blaspsoft\Blasp\Facades\Blasp;

$sentence = 'Cette phrase est merdique';
$check = Blasp::check($sentence, 'fr');
```
The returned object will contain the following properties:

- **sourceString**: The original string you passed.
Expand Down Expand Up @@ -82,15 +76,8 @@ $request->merge(['sentence' => 'This is f u c k 1 n g awesome!']);
$validated = $request->validate([
'sentence' => ['blasp_check'],
]);

// If the sentence contains profanities, validation will fail.
```
or for french
```php
$validated = $request->validate([
'sentence' => ['blasp_check:fr'],
]);
```

### Configuration

Blasp uses a configuration file (`config/blasp.php`) to manage the list of profanities, separators, and substitutions. You can publish the configuration file using the following Artisan command:
Expand Down
51 changes: 4 additions & 47 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
|
|
*/
'languages' => ['en', 'fr'],
'languages' => ['en'],

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -95,7 +95,7 @@
'/p/' => ['p', 'ρ', 'Ρ', '', 'þ'],
'/q/' => ['q'],
'/r/' => ['r', '®'],
'/s/' => ['s', '5', '$', '§', 'ß', 'Ś', 'ś', 'Š', 'š'],
'/s/' => ['s', '5', '\$', '§', 'ß', 'Ś', 'ś', 'Š', 'š'],
'/t/' => ['t', 'Τ', 'τ'],
'/u/' => ['u', 'υ', 'µ', 'û', 'ü', 'ù', 'ú', 'ū', 'Û', 'Ü', 'Ù', 'Ú', 'Ū'],
'/v/' => ['v', 'υ', 'ν'],
Expand Down Expand Up @@ -136,15 +136,8 @@
'flicker',
'analyst',
'cocktail',
'musicals hit',
],
'fr' => [
'passeur',
'classe',
'passage',
'assumer',
'passant',
'bassiste',
]
],


Expand Down Expand Up @@ -462,7 +455,6 @@
'cuntass',
'cunteyed',
'cuntface',
'cuntfuck',
'cuntfucker',
'cunthole',
'cuntlick',
Expand Down Expand Up @@ -637,7 +629,6 @@
'fuckbutt',
'fuckbutter',
'fucked',
'fuckedup',
'fucker',
'fuckers',
'fuckersucker',
Expand All @@ -652,7 +643,6 @@
'fuckina',
'fucking',
'fuckingbitch',
'fuckingcunt',
'fuckinnuts',
'fuckinright',
'fuckit',
Expand Down Expand Up @@ -742,7 +732,7 @@
'hardon',
'headfuck',
'heeb',
'hells',
'hell',
'herpes',
'hijacker',
'hijacking',
Expand Down Expand Up @@ -782,7 +772,6 @@
'incest',
'insest',
'internet wife',
'intheass',
'inthebuff',
'jackass',
'jackoff',
Expand Down Expand Up @@ -1461,37 +1450,5 @@
'zipperhea',
'zipper head',
],
'fr' => [
'con',
'connard',
'connasse',
'merde',
'merdique',
'putain',
'enculé',
'salope',
'batard',
'bordel',
'fils de pute',
'pute',
'cul',
'abruti',
'crétin',
'imbécile',
'ordure',
'débile',
'dégénéré',
'foutre',
'chiant',
'chiotte',
'bouffon',
'gros con',
'pédé',
'tapette',
'bite',
'couille',
'enfoiré',
'trou du cul',
]
],
];
8 changes: 5 additions & 3 deletions src/BlaspExpressionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private function loadConfiguration(): void

$this->validateChosenLanguage();

$this->profanities = config('blasp.profanities')[$this->chosenLanguage];
$this->profanities = config('blasp.profanities')[$this->chosenLanguage];
$this->separators = config('blasp.separators');
$this->substitutions = config('blasp.substitutions');
}
Expand Down Expand Up @@ -157,6 +157,7 @@ private function generateEscapedExpression(array $characters = [], array $escape
$regex = $escapedCharacters;

foreach ($characters as $character) {

$regex[] = preg_quote($character, '/');
}

Expand Down Expand Up @@ -190,8 +191,9 @@ private function generateProfanityExpression($profanity): string

$expression = str_replace(self::SEPARATOR_PLACEHOLDER, $this->separatorExpression, $expression);

$expression = '/' . $expression . '(?:s?)\b/i';

// Allow for non-word characters or spaces around the profanity
$expression = '/' . $expression . '/i';

return $expression;
}

Expand Down
4 changes: 2 additions & 2 deletions src/BlaspService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Blaspsoft\Blasp;

use Blaspsoft\Blasp\Abstracts\StringNormalizer;
use Blaspsoft\Blasp\Normalizers\Normalize;
use Exception;
use Blaspsoft\Blasp\Normalizers\Normalize;
use Blaspsoft\Blasp\Abstracts\StringNormalizer;

class BlaspService extends BlaspExpressionService
{
Expand Down
123 changes: 0 additions & 123 deletions tests/BlaspCheckFrenchTest.php

This file was deleted.

Loading

0 comments on commit ec96e3e

Please sign in to comment.