MTM Fix UpdateHandler error from OwnYourSwarm checkin #84
2 changed files with 24 additions and 1 deletions
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 <noreply@anthropic.com>
commit
e8e2bff5e4
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue