From e8e2bff5e4c7a1775e9dcfabf9719b21d02ddf43 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Wed, 18 Mar 2026 17:43:57 +0000 Subject: [PATCH] Fix UpdateHandler crash when replace.content is a rich-text object OwnYourSwarm sends content as an array of objects with `value` and `html` keys per the Micropub spec. The handler now handles both forms: plain strings and rich objects, preferring `html` over `value`. Co-Authored-By: Claude Sonnet 4.6 --- .../Micropub/Handlers/UpdateHandler.php | 2 +- tests/Feature/MicropubControllerTest.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/Services/Micropub/Handlers/UpdateHandler.php b/app/Services/Micropub/Handlers/UpdateHandler.php index 354cdbdd..e252b243 100644 --- a/app/Services/Micropub/Handlers/UpdateHandler.php +++ b/app/Services/Micropub/Handlers/UpdateHandler.php @@ -53,7 +53,7 @@ class UpdateHandler implements MicropubHandlerInterface if ($data->updateReplace !== null) { foreach ($data->updateReplace as $property => $value) { match ($property) { - 'content' => $note->note = $value[0], + 'content' => $note->note = is_array($value[0]) ? ($value[0]['html'] ?? $value[0]['value'] ?? null) : $value[0], 'syndication' => $this->applySyndication($note, $value), default => null, }; diff --git a/tests/Feature/MicropubControllerTest.php b/tests/Feature/MicropubControllerTest.php index 10d129c0..f694916b 100644 --- a/tests/Feature/MicropubControllerTest.php +++ b/tests/Feature/MicropubControllerTest.php @@ -538,6 +538,29 @@ class MicropubControllerTest extends TestCase $this->assertSame('replaced content', $note->content); } + #[Test] + public function micropub_client_api_request_updates_existing_note_with_rich_text_content(): void + { + $note = Note::factory()->create(); + $response = $this->postJson( + '/api/post', + [ + 'action' => 'update', + 'url' => $note->uri, + 'replace' => [ + 'content' => [['value' => 'plain text', 'html' => 'html version']], + ], + ], + ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] + ); + $response + ->assertJson(['response' => 'updated']) + ->assertSuccessful(); + + $note->refresh(); + $this->assertSame('html version', $note->content); + } + #[Test] public function micropub_client_api_request_updates_note_syndication_links(): void { -- 2.55.0