From cc539dbfdcd98c6469277bd9f71030debd1a2283 Mon Sep 17 00:00:00 2001 From: Propaganistas Date: Thu, 6 Apr 2023 08:18:53 +0200 Subject: [PATCH 1/7] return null --- src/Casts/PurifyHtmlOnGet.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Casts/PurifyHtmlOnGet.php b/src/Casts/PurifyHtmlOnGet.php index bfa2138..d1a3088 100644 --- a/src/Casts/PurifyHtmlOnGet.php +++ b/src/Casts/PurifyHtmlOnGet.php @@ -19,6 +19,10 @@ class PurifyHtmlOnGet extends Caster implements CastsAttributes */ public function get($model, $key, $value, $attributes) { + if (is_null($value)) { + return null; + } + return Purify::config($this->config)->clean($value); } From 1c4307138a0775e723ef2d2aca4911064bcb9c1c Mon Sep 17 00:00:00 2001 From: Propaganistas Date: Thu, 6 Apr 2023 08:20:38 +0200 Subject: [PATCH 2/7] update docblocks --- src/Casts/PurifyHtmlOnGet.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Casts/PurifyHtmlOnGet.php b/src/Casts/PurifyHtmlOnGet.php index d1a3088..38f1944 100644 --- a/src/Casts/PurifyHtmlOnGet.php +++ b/src/Casts/PurifyHtmlOnGet.php @@ -15,7 +15,7 @@ class PurifyHtmlOnGet extends Caster implements CastsAttributes * @param mixed $value * @param array $attributes * - * @return string|array + * @return string|array|null */ public function get($model, $key, $value, $attributes) { @@ -34,7 +34,7 @@ public function get($model, $key, $value, $attributes) * @param mixed $value * @param array $attributes * - * @return array|string + * @return array|string|null */ public function set($model, $key, $value, $attributes) { From 9a459fc4cc912f163fa7383a609deb726edee9ee Mon Sep 17 00:00:00 2001 From: Propaganistas Date: Thu, 6 Apr 2023 08:21:12 +0200 Subject: [PATCH 3/7] set null --- src/Casts/PurifyHtmlOnSet.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Casts/PurifyHtmlOnSet.php b/src/Casts/PurifyHtmlOnSet.php index a66cea9..53981fb 100644 --- a/src/Casts/PurifyHtmlOnSet.php +++ b/src/Casts/PurifyHtmlOnSet.php @@ -15,7 +15,7 @@ class PurifyHtmlOnSet extends Caster implements CastsAttributes * @param mixed $value * @param array $attributes * - * @return string|array + * @return string|array|null */ public function get($model, string $key, $value, array $attributes) { @@ -30,10 +30,14 @@ public function get($model, string $key, $value, array $attributes) * @param mixed $value * @param array $attributes * - * @return array|string + * @return array|string|null */ public function set($model, string $key, $value, array $attributes) { + if (is_null($value)) { + return null; + } + return Purify::config($this->config)->clean($value); } } From 116a976a435cf6a9b45097dab5f2da4d9e2c0fe5 Mon Sep 17 00:00:00 2001 From: Propaganistas Date: Thu, 6 Apr 2023 08:24:10 +0200 Subject: [PATCH 4/7] add tests --- tests/CastsTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/CastsTest.php b/tests/CastsTest.php index 3174893..7410575 100644 --- a/tests/CastsTest.php +++ b/tests/CastsTest.php @@ -35,6 +35,14 @@ public function test_purifies_on_get_with_custom_config() $this->assertEquals($this->testInput, $model->getAttributes()['body']); $this->assertEquals('

Testbar

', $model->body); } + + public function test_returns_null_on_get_when_value_is_null() + { + $model = new PurifyingDefaultOnGetModel(); + $model->body = null; + + $this->assertNull($model->body); + } public function test_purifies_on_set_with_default_config() { @@ -59,6 +67,14 @@ public function test_purifies_on_set_with_custom_config() $this->assertEquals('

Testbar

', $model->getAttributes()['body']); } + + public function test_sets_null_on_set_when_value_is_null() + { + $model = new PurifyingDefaultOnSetModel(); + $model->body = null; + + $this->assertNull($model->getAttributes()['body']); + } } class PurifyingDefaultOnGetModel extends Model From 277260a26ef37b0058165dfa4c2f4cb67639da18 Mon Sep 17 00:00:00 2001 From: Propaganistas Date: Thu, 6 Apr 2023 08:27:00 +0200 Subject: [PATCH 5/7] styleci --- src/Casts/PurifyHtmlOnGet.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Casts/PurifyHtmlOnGet.php b/src/Casts/PurifyHtmlOnGet.php index 38f1944..84115f4 100644 --- a/src/Casts/PurifyHtmlOnGet.php +++ b/src/Casts/PurifyHtmlOnGet.php @@ -20,9 +20,9 @@ class PurifyHtmlOnGet extends Caster implements CastsAttributes public function get($model, $key, $value, $attributes) { if (is_null($value)) { - return null; + return null; } - + return Purify::config($this->config)->clean($value); } From cd1456b5f0868cff4125994b6d475152fc69463e Mon Sep 17 00:00:00 2001 From: Propaganistas Date: Thu, 6 Apr 2023 08:27:16 +0200 Subject: [PATCH 6/7] styleci --- src/Casts/PurifyHtmlOnSet.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Casts/PurifyHtmlOnSet.php b/src/Casts/PurifyHtmlOnSet.php index 53981fb..a2d99f1 100644 --- a/src/Casts/PurifyHtmlOnSet.php +++ b/src/Casts/PurifyHtmlOnSet.php @@ -35,9 +35,9 @@ public function get($model, string $key, $value, array $attributes) public function set($model, string $key, $value, array $attributes) { if (is_null($value)) { - return null; + return null; } - + return Purify::config($this->config)->clean($value); } } From 86429057ec0efae0d1913b7810c3e4c33323808f Mon Sep 17 00:00:00 2001 From: Propaganistas Date: Thu, 6 Apr 2023 08:27:35 +0200 Subject: [PATCH 7/7] styleci --- tests/CastsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CastsTest.php b/tests/CastsTest.php index 7410575..b0061fb 100644 --- a/tests/CastsTest.php +++ b/tests/CastsTest.php @@ -35,7 +35,7 @@ public function test_purifies_on_get_with_custom_config() $this->assertEquals($this->testInput, $model->getAttributes()['body']); $this->assertEquals('

Testbar

', $model->body); } - + public function test_returns_null_on_get_when_value_is_null() { $model = new PurifyingDefaultOnGetModel(); @@ -67,7 +67,7 @@ public function test_purifies_on_set_with_custom_config() $this->assertEquals('

Testbar

', $model->getAttributes()['body']); } - + public function test_sets_null_on_set_when_value_is_null() { $model = new PurifyingDefaultOnSetModel();