Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ghost/core/core/server/api/endpoints/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const membersService = require('../../services/members');
const settingsCache = require('../../../shared/settings-cache');
const tpl = require('@tryghost/tpl');
const _ = require('lodash');
const {slugify} = require('@tryghost/string');

const messages = {
memberNotFound: 'Member not found.',
Expand Down Expand Up @@ -378,7 +379,9 @@ const controller = {
type: 'csv',
value() {
const datetime = (new Date()).toJSON().substring(0, 10);
return `members.${datetime}.csv`;
const title = settingsCache.get('title');
const titlePrefix = title ? `${slugify(title)}.` : '';
return `${titlePrefix}ghost.members.${datetime}.csv`;
Comment on lines +383 to +384
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard against empty slug output to preserve the documented fallback filename.

At Line 383, fallback is based on raw title truthiness. If title exists but slugifies to an empty string, Line 384 can emit .ghost.members.{date}.csv instead of ghost.members.{date}.csv.

Suggested fix (fallback on slug result, not raw title)
-                    const title = settingsCache.get('title');
-                    const titlePrefix = title ? `${slugify(title)}.` : '';
+                    const title = settingsCache.get('title');
+                    const titleSlug = title ? slugify(title) : '';
+                    const titlePrefix = titleSlug ? `${titleSlug}.` : '';
                     return `${titlePrefix}ghost.members.${datetime}.csv`;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ghost/core/core/server/api/endpoints/members.js` around lines 383 - 384,
Compute the slug once and base the fallback on the slug result (not raw title):
call slugify(title) into a local variable (e.g., slug), then set titlePrefix =
slug ? `${slug}.` : '' so you avoid emitting a leading dot when slugify(title)
returns an empty string; keep the existing return
`${titlePrefix}ghost.members.${datetime}.csv`.

}
Comment on lines +382 to 385
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Filename prefix logic may never reach clients because CSV serializer hardcodes Content-Disposition.

At Line 384 you return a prefixed filename, but ghost/core/core/server/api/endpoints/utils/serializers/output/members.js (Lines 469-493 in provided context) still sets Content-Disposition to members.{YYYY-MM-DD}.csv. If that stream serializer runs for this endpoint, it overrides this PR’s header contract and the new filename format won’t be applied.

Suggested fix (propagate endpoint filename into stream serializer)
# ghost/core/core/server/api/endpoints/utils/serializers/output/members.js
-            res.setHeader('Content-Disposition', `attachment; filename="members.${datetime}.csv"`);
+            const fallbackFilename = `members.${datetime}.csv`;
+            const disposition = res.getHeader('Content-Disposition');
+            if (!disposition) {
+                res.setHeader('Content-Disposition', `attachment; filename="${fallbackFilename}"`);
+            }
# ghost/core/core/server/api/endpoints/members.js
                 value() {
                     const datetime = (new Date()).toJSON().substring(0, 10);
                     const title = settingsCache.get('title');
                     const titlePrefix = title ? `${slugify(title)}.` : '';
                     return `${titlePrefix}ghost.members.${datetime}.csv`;
                 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ghost/core/core/server/api/endpoints/members.js` around lines 382 - 385, The
endpoint builds a prefixed filename (the const that returns
`${titlePrefix}ghost.members.${datetime}.csv`) but the stream serializer
membersCsvSerializer in serializers/output/members.js still hardcodes
Content-Disposition to `members.{YYYY-MM-DD}.csv`, so the header is overridden;
update the stream serializer to accept a filename option (or read
resp.locals.filename) and use that value when setting Content-Disposition, and
update the members endpoint (where the filename is constructed) to pass the
computed filename into membersCsvSerializer (or set resp.locals.filename) so the
serializer uses the endpoint-provided name rather than the hardcoded one.

},
contentType: 'text/csv',
Expand Down
Loading