@@ -47,14 +47,16 @@ private static function getErrorObject(string $exceptionMessage): NovaEditorJsDa
47
47
* @param array $attributes
48
48
* @return NovaEditorJsData|null
49
49
*/
50
- public function get ($ model , string $ key , $ value , array $ attributes )
50
+ public function get ($ model , string $ key , $ value , array $ attributes ): ? NovaEditorJsData
51
51
{
52
- if ($ value === null ) {
53
- return null ;
54
- }
55
-
56
52
try {
57
- return new NovaEditorJsData (json_decode ($ value , true , 512 , JSON_THROW_ON_ERROR ));
53
+ // Recursively decode JSON, to solve a bug where the JSON is double-encoded.
54
+ while (is_string ($ value ) && ! empty ($ value )) {
55
+ $ value = json_decode ($ value , true , 512 , JSON_THROW_ON_ERROR );
56
+ }
57
+
58
+ // Return null if the new value is null
59
+ return $ value === null ? null : new NovaEditorJsData ($ value );
58
60
} catch (JsonException $ exception ) {
59
61
return self ::getErrorObject ($ exception ->getMessage ());
60
62
}
@@ -67,9 +69,9 @@ public function get($model, string $key, $value, array $attributes)
67
69
* @param string $key
68
70
* @param mixed $value
69
71
* @param array $attributes
70
- * @return mixed
72
+ * @return array
71
73
*/
72
- public function set ($ model , string $ key , $ value , array $ attributes )
74
+ public function set ($ model , string $ key , $ value , array $ attributes ): array
73
75
{
74
76
if ($ value === null ) {
75
77
return [
@@ -83,7 +85,7 @@ public function set($model, string $key, $value, array $attributes)
83
85
}
84
86
85
87
return [
86
- $ key => json_encode ($ value ),
88
+ $ key => is_string ( $ value ) ? $ value : json_encode ($ value ),
87
89
];
88
90
}
89
91
}
0 commit comments