Skip to content

Commit

Permalink
Allowed null for html and excerpt on posts (#245)
Browse files Browse the repository at this point in the history
closes https://linear.app/ghost/issue/AP-551

It's possible that posts have `null` for their `html` and `excerpt`
properties, and we weren't handling that, resulting in errors!
  • Loading branch information
allouis authored Jan 7, 2025
1 parent 16a91e9 commit b4ff448
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions features/create-article-from-post.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Feature: Deliver Create(Article) activities when a post.published webhook is rec
Then a "Create(Article)" activity is in the Outbox
And the found "Create(Article)" has property "object.attributedTo"

Scenario: We recieve a webhook for the post.published event and the post has no content
Given a valid "post.published(no content)" webhook
When it is sent to the webhook endpoint
Then the request is accepted
Then a "Create(Article)" activity is in the Outbox
And the found "Create(Article)" has property "object.attributedTo"

Scenario: We recieve a webhook for the post.published event with an old signature
Given a valid "post.published" webhook
When it is sent to the webhook endpoint with an old signature
Expand Down
16 changes: 16 additions & 0 deletions features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1007,11 +1007,27 @@ const webhooks = {
},
},
},
'post.published(no content)': {
post: {
current: {
uuid: '986108d9-3d50-4701-9808-eab62e0885cf',
title: 'This is a title.',
html: null,
feature_image: null,
visibility: 'paid',
published_at: '1970-01-01T00:00:00.000Z',
url: 'http://fake-external-activitypub/post/',
excerpt: null,
},
},
},
};

const endpoints = {
'post.published':
'http://fake-ghost-activitypub/.ghost/activitypub/webhooks/post/published',
'post.published(no content)':
'http://fake-ghost-activitypub/.ghost/activitypub/webhooks/post/published',
};

Given('a valid {string} webhook', function (string) {
Expand Down
4 changes: 2 additions & 2 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import { getSiteSettings } from './helpers/ghost';
const PostSchema = z.object({
uuid: z.string().uuid(),
title: z.string(),
html: z.string(),
excerpt: z.string(),
html: z.string().nullable(),
excerpt: z.string().nullable(),
feature_image: z.string().url().nullable(),
published_at: z.string().datetime(),
url: z.string().url(),
Expand Down

0 comments on commit b4ff448

Please sign in to comment.