From bb48d3623a29ed9037df44b31526cdabb69f49d5 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 2 Oct 2024 10:13:43 +0100 Subject: [PATCH] Increased feature image alt text length to 191 chars no issue - removed the 125 char soft limit so the full 191 char db field length can be used --- ghost/core/core/server/data/schema/schema.js | 4 ++-- .../admin/__snapshots__/posts.test.js.snap | 18 ++++++++++++++++ ghost/core/test/e2e-api/admin/posts.test.js | 21 ++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/ghost/core/core/server/data/schema/schema.js b/ghost/core/core/server/data/schema/schema.js index 7d1b113618..17c536b13a 100644 --- a/ghost/core/core/server/data/schema/schema.js +++ b/ghost/core/core/server/data/schema/schema.js @@ -113,7 +113,7 @@ module.exports = { meta_description: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 500}}}, email_subject: {type: 'string', maxlength: 300, nullable: true}, frontmatter: {type: 'text', maxlength: 65535, nullable: true}, - feature_image_alt: {type: 'string', maxlength: 191, nullable: true, validations: {isLength: {max: 125}}}, + feature_image_alt: {type: 'string', maxlength: 191, nullable: true}, feature_image_caption: {type: 'text', maxlength: 65535, nullable: true}, email_only: {type: 'boolean', nullable: false, defaultTo: false} }, @@ -418,7 +418,7 @@ module.exports = { post_status: {type: 'string', maxlength: 50, nullable: true, validations: {isIn: [['draft', 'published', 'scheduled', 'sent']]}}, reason: {type: 'string', maxlength: 50, nullable: true}, feature_image: {type: 'string', maxlength: 2000, nullable: true}, - feature_image_alt: {type: 'string', maxlength: 191, nullable: true, validations: {isLength: {max: 125}}}, + feature_image_alt: {type: 'string', maxlength: 191, nullable: true}, feature_image_caption: {type: 'text', maxlength: 65535, nullable: true}, custom_excerpt: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 300}}} }, diff --git a/ghost/core/test/e2e-api/admin/__snapshots__/posts.test.js.snap b/ghost/core/test/e2e-api/admin/__snapshots__/posts.test.js.snap index 3e90545e51..e666a2cdb2 100644 --- a/ghost/core/test/e2e-api/admin/__snapshots__/posts.test.js.snap +++ b/ghost/core/test/e2e-api/admin/__snapshots__/posts.test.js.snap @@ -1457,6 +1457,24 @@ Object { } `; +exports[`Posts API Create Errors if feature_image_alt is too long 1: [body] 1`] = ` +Object { + "errors": Array [ + Object { + "code": null, + "context": StringMatching /\\.\\*post_revisions\\\\\\.feature_image_alt\\] exceeds maximum length of 191 characters\\.\\*/, + "details": null, + "ghostErrorCode": null, + "help": null, + "id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, + "message": "Validation error, cannot save post.", + "property": null, + "type": "ValidationError", + }, + ], +} +`; + exports[`Posts API Create Errors with an invalid lexical state object 1: [body] 1`] = ` Object { "errors": Array [ diff --git a/ghost/core/test/e2e-api/admin/posts.test.js b/ghost/core/test/e2e-api/admin/posts.test.js index 7b837f9ff1..04c64403e1 100644 --- a/ghost/core/test/e2e-api/admin/posts.test.js +++ b/ghost/core/test/e2e-api/admin/posts.test.js @@ -390,6 +390,25 @@ describe('Posts API', function () { }); }); + it('Errors if feature_image_alt is too long', async function () { + const post = { + title: 'Feature image alt too long', + feature_image_alt: 'a'.repeat(201) + }; + + await agent + .post('/posts/?formats=mobiledoc,lexical,html') + .body({posts: [post]}) + .expectStatus(422) + .matchBodySnapshot({ + errors: [{ + id: anyErrorId, + // TODO: this should be `posts.feature_image_alt` but we're hitting revision errors first + context: stringMatching(/.*post_revisions\.feature_image_alt] exceeds maximum length of 191 characters.*/) + }] + }); + }); + it('Clears all page html fields when creating published post', async function () { const totalPageCount = await models.Post.where({type: 'page'}).count(); should.exist(totalPageCount, 'total page count'); @@ -877,7 +896,7 @@ describe('Posts API', function () { 'content-version': anyContentVersion, etag: anyEtag }); - + const convertedPost = conversionResponse.body.posts[0]; const expectedConvertedLexical = convertedPost.lexical; await agent