Skip to content

Commit

Permalink
Use composer/pcre to handle preg_* (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed Aug 22, 2024
1 parent a72f99c commit 4a69c8a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Helpers;

use Composer\Pcre\Preg;
use Spatie\Url\Url as SpatieUrl;

class Helper
Expand Down Expand Up @@ -37,7 +38,7 @@ public static function urlFormat(string $value, ?int $limit = null, bool $scheme

// Optionally strip scheme
if ($scheme === false) {
$value = preg_replace('{^http(s)?://}', '', $value);
$value = Preg::replace('{^http(s)?://}', '', $value);
$hostLen = strlen($sUrl->getHost());
}

Expand Down Expand Up @@ -96,7 +97,7 @@ public static function publicPathCollisionList()
public static function collisionCandidateFilter($value)
{
return collect($value)
->filter(fn($value) => preg_match('/^([0-9a-zA-Z\-])+$/', $value))
->filter(fn($value) => Preg::isMatch('/^([0-9a-zA-Z\-])+$/', $value))
->reject(fn($value) => in_array($value, config('urlhub.reserved_keyword')))
->unique();
}
Expand Down
5 changes: 2 additions & 3 deletions app/Rules/AlphaNumHyphen.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Rules;

use Composer\Pcre\Preg;
use Illuminate\Contracts\Validation\ValidationRule;

/**
Expand All @@ -12,9 +13,7 @@ class AlphaNumHyphen implements ValidationRule
{
public function validate(string $attribute, mixed $value, \Closure $fail): void
{
$rule = preg_match('/^[\pL\pM\pN-]+$/u', $value);

if ($rule === false || $rule === 0) {
if (! Preg::isMatch('/^[\pL\pM\pN-]+$/u', $value)) {
$fail('The :attribute may only contain letters, numbers and hyphens.');
}
}
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"require": {
"php": "^8.2",
"blade-ui-kit/blade-icons": "^1.6",
"composer/pcre": "^3.3",
"embed/embed": "^4.4",
"endroid/qr-code": "^5.0",
"filament/widgets": "^3.2",
Expand Down

0 comments on commit 4a69c8a

Please sign in to comment.