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>
This commit is contained in:
parent
4451fc247e
commit
e8e2bff5e4
2 changed files with 24 additions and 1 deletions
|
|
@ -53,7 +53,7 @@ class UpdateHandler implements MicropubHandlerInterface
|
||||||
if ($data->updateReplace !== null) {
|
if ($data->updateReplace !== null) {
|
||||||
foreach ($data->updateReplace as $property => $value) {
|
foreach ($data->updateReplace as $property => $value) {
|
||||||
match ($property) {
|
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),
|
'syndication' => $this->applySyndication($note, $value),
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -538,6 +538,29 @@ class MicropubControllerTest extends TestCase
|
||||||
$this->assertSame('replaced content', $note->content);
|
$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]
|
#[Test]
|
||||||
public function micropub_client_api_request_updates_note_syndication_links(): void
|
public function micropub_client_api_request_updates_note_syndication_links(): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue