Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
28 changes: 21 additions & 7 deletions components/subreddit-picker/CustomizePostDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export const CustomizePostDialog: React.FC<CustomizePostDialogProps> = ({
const displayTitle = useCustomTitle ? customTitle : globalTitle;
const displayBody = useCustomBody ? customBody : globalBody;

const bodyError = bodyRequired && !displayBody.trim()
? 'Description is required for this community'
: null;

return (
<>
<Dialog open={open} onOpenChange={onOpenChange}>
Expand Down Expand Up @@ -255,18 +259,28 @@ export const CustomizePostDialog: React.FC<CustomizePostDialogProps> = ({
<span className="hidden sm:inline">AI</span>
</button>
</div>
<div className="flex justify-end mt-1">
<div className="flex justify-between items-center mt-1">
{bodyError ? (
<p className="text-xs text-red-500">{bodyError}</p>
) : (
<span />
)}
<span className={`text-xs ${displayBody.length > bodyMaxLength * 0.9 ? 'text-yellow-500' : 'text-muted-foreground'}`}>
{displayBody.length}/{bodyMaxLength}
</span>
</div>
</div>
) : (
<div className="mt-2 px-3 py-2 bg-muted/50 rounded-md text-sm text-muted-foreground">
{globalBody ? (
<>Using global: &quot;{globalBody.slice(0, 80)}{globalBody.length > 80 ? '...' : ''}&quot;</>
) : (
<span className="italic">No description set</span>
<div className="mt-2">
<div className="px-3 py-2 bg-muted/50 rounded-md text-sm text-muted-foreground">
{globalBody ? (
<>Using global: &quot;{globalBody.slice(0, 80)}{globalBody.length > 80 ? '...' : ''}&quot;</>
) : (
<span className="italic">No description set</span>
)}
</div>
{bodyError && (
<p className="text-xs text-red-500 mt-1">{bodyError}</p>
)}
</div>
)}
Expand All @@ -289,7 +303,7 @@ export const CustomizePostDialog: React.FC<CustomizePostDialogProps> = ({
<Button variant="outline" onClick={() => onOpenChange(false)} className="cursor-pointer">
Cancel
</Button>
<Button onClick={handleSave} className="cursor-pointer">
<Button onClick={handleSave} disabled={!!bodyError} className="cursor-pointer">
Save
</Button>
</DialogFooter>
Expand Down
24 changes: 12 additions & 12 deletions lib/preflightValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,18 @@ function validateBody(input: PreflightInput): ValidationIssue[] {
if (!reqs) continue;

// Body required check
if (reqs.body_restriction_policy === 'required' && !body.trim()) {
issues.push({
code: 'BODY_REQUIRED',
severity: 'error',
subreddit,
message: `r/${subreddit} requires a description`,
suggestion: 'Add a description to your post',
field: 'body',
expectedCategory: 'fixable_now',
});
continue;
}
// if (reqs.body_restriction_policy === 'required' && !body.trim()) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reinstate BODY_REQUIRED in preflight validation

Commenting out this branch removes the only global check that blocks submissions when a subreddit requires a description, so validatePreflight can now return canProceed=true for empty bodies and the queue/review flow will allow posting until Reddit rejects it downstream. The new inline check in CustomizePostDialog does not cover this because it only runs if that dialog is opened (and customization is gated by paid/trial in pages/index.tsx), so free users and any non-customized subreddit path lose required-body protection entirely.

Useful? React with 👍 / 👎.

// issues.push({
// code: 'BODY_REQUIRED',
// severity: 'error',
// subreddit,
// message: `r/${subreddit} requires a description`,
// suggestion: 'Add a description to your post',
// field: 'body',
// expectedCategory: 'fixable_now',
// });
// continue;
// }
Comment on lines +275 to +286
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Restore server-side/preflight BODY_REQUIRED enforcement.

Line 275-Line 286 currently bypasses required-body validation by commenting out the check. This regresses preflight guarantees and allows invalid payloads to pass validatePreflight when subreddit policy requires a body.

🔧 Proposed fix
-    // Body required check
-    // if (reqs.body_restriction_policy === 'required' && !body.trim()) {
-    //   issues.push({
-    //     code: 'BODY_REQUIRED',
-    //     severity: 'error',
-    //     subreddit,
-    //     message: `r/${subreddit} requires a description`,
-    //     suggestion: 'Add a description to your post',
-    //     field: 'body',
-    //     expectedCategory: 'fixable_now',
-    //   });
-    //   continue;
-    // }
+    // Body required check
+    if (reqs.body_restriction_policy === 'required' && !body.trim()) {
+      issues.push({
+        code: 'BODY_REQUIRED',
+        severity: 'error',
+        subreddit,
+        message: `r/${subreddit} requires a description`,
+        suggestion: 'Add a description to your post',
+        field: 'body',
+        expectedCategory: 'fixable_now',
+      });
+      continue;
+    }

As per coding guidelines, "Never bypass validation" and "Always validate inputs."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/preflightValidation.ts` around lines 275 - 286, Re-enable the server-side
required-body validation in the preflight routine by restoring the conditional
that checks reqs.body_restriction_policy === 'required' and empty body
(body.trim() === ''), and when triggered push the same issue object back onto
issues (code: 'BODY_REQUIRED', severity: 'error', subreddit, message:
`r/${subreddit} requires a description`, suggestion: 'Add a description to your
post', field: 'body', expectedCategory: 'fixable_now') and then continue; locate
this logic near the validatePreflight / preflight validation loop that currently
has the commented block referencing reqs.body_restriction_policy and issues and
restore it unchanged so required-body policy is enforced server-side.


// Min length (only if body exists)
if (body && reqs.body_text_min_length && body.length < reqs.body_text_min_length) {
Expand Down
Loading