From ffab8f2b50856a4ff4972bd681377058aefb7467 Mon Sep 17 00:00:00 2001
From: Akul Mehta <42812604+akulmehta@users.noreply.github.com>
Date: Wed, 17 Apr 2024 16:10:33 -0400
Subject: [PATCH 1/2] Added null coalescing to preg_replace 3rd parameter
---
resources/views/components/editable.blade.php | 2 +-
resources/views/components/row.blade.php | 2 +-
src/Footer.php | 2 +-
tests/Feature/ExportTest.php | 4 ++--
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/resources/views/components/editable.blade.php b/resources/views/components/editable.blade.php
index c3749909..f03e250d 100644
--- a/resources/views/components/editable.blade.php
+++ b/resources/views/components/editable.blade.php
@@ -12,7 +12,7 @@
@php
$resolveContent = function (string $currentTable, string $field, \Illuminate\Database\Eloquent\Model|\stdClass $row): ?string {
$currentField = $field;
- $replace = fn($content) => preg_replace('##is', '', $content);
+ $replace = fn($content) => preg_replace('##is', '', $content ?? '');
/** @codeCoverageIgnore */
if (str_contains($currentField, '.')) {
diff --git a/resources/views/components/row.blade.php b/resources/views/components/row.blade.php
index 000cc696..aeab0990 100644
--- a/resources/views/components/row.blade.php
+++ b/resources/views/components/row.blade.php
@@ -30,7 +30,7 @@
@php
$content = $row->{$column->field} ?? '';
$contentClassField = $column->contentClassField != '' ? $row->{$column->contentClassField} : '';
- $content = preg_replace('##is', '', $content);
+ $content = preg_replace('##is', '', $content ?? '');
$field = $column->dataField != '' ? $column->dataField : $column->field;
$contentClass = $column->contentClasses;
diff --git a/src/Footer.php b/src/Footer.php
index 1f019521..d6a655c8 100644
--- a/src/Footer.php
+++ b/src/Footer.php
@@ -77,7 +77,7 @@ public function includeViewOnBottom(string $viewPath): Footer
public function pageName(string $pageName = 'page'): Footer
{
- $pageName = (string) preg_replace('/[^a-z0-9]/i', '', $pageName);
+ $pageName = (string) preg_replace('/[^a-z0-9]/i', '', $pageName ?? '');
if (trim($pageName) === '') {
$pageName = 'page';
diff --git a/tests/Feature/ExportTest.php b/tests/Feature/ExportTest.php
index 128a8db9..5d270eb0 100644
--- a/tests/Feature/ExportTest.php
+++ b/tests/Feature/ExportTest.php
@@ -122,7 +122,7 @@
$actual = collect(explode('', $content))
->filter(fn ($heading) => strlen($heading) > 0)
->transform(function ($line) use ($delimiter, $separator) {
- $arrayLine = explode($separator, preg_replace('/[^A-Za-z0-9.!?|@,á" ]/', '', $line));
+ $arrayLine = explode($separator, preg_replace('/[^A-Za-z0-9.!?|@,á" ]/', '', $line ?? ''));
$rows = collect($arrayLine)
->transform(fn ($row) => trim($row, $delimiter))
@@ -180,7 +180,7 @@
$actual = collect($content)
->filter(fn ($heading) => strlen($heading) > 0)
->transform(function ($line) use ($delimiter, $separator) {
- $arrayLine = explode($separator, preg_replace('/[^A-Za-z0-9.!?|@,á" ]/', '', $line));
+ $arrayLine = explode($separator, preg_replace('/[^A-Za-z0-9.!?|@,á" ]/', '', $line ?? ''));
$rows = collect($arrayLine)
->transform(fn ($row) => trim($row, $delimiter))
From f99df7f198a96b155b75bdc7654bad2cd2c109ec Mon Sep 17 00:00:00 2001
From: Akul Mehta <42812604+akulmehta@users.noreply.github.com>
Date: Wed, 17 Apr 2024 16:14:36 -0400
Subject: [PATCH 2/2] Fix larastan $pageName always there.
---
src/Footer.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Footer.php b/src/Footer.php
index d6a655c8..1f019521 100644
--- a/src/Footer.php
+++ b/src/Footer.php
@@ -77,7 +77,7 @@ public function includeViewOnBottom(string $viewPath): Footer
public function pageName(string $pageName = 'page'): Footer
{
- $pageName = (string) preg_replace('/[^a-z0-9]/i', '', $pageName ?? '');
+ $pageName = (string) preg_replace('/[^a-z0-9]/i', '', $pageName);
if (trim($pageName) === '') {
$pageName = 'page';