-
Notifications
You must be signed in to change notification settings - Fork 429
fix: enforce minLength on update_release body to block placeholder submissions #39713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,14 @@ const SAMPLE_VALIDATION_CONFIG = { | |
| }, | ||
| }, | ||
| }, | ||
| update_release: { | ||
| defaultMax: 1, | ||
| fields: { | ||
| tag: { type: "string", sanitize: true, maxLength: 256 }, | ||
| operation: { required: true, type: "string", enum: ["replace", "append", "prepend"] }, | ||
| body: { required: true, type: "string", sanitize: true, maxLength: 65000, minLength: 20 }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const ISSUE_CLOSING_KEYWORDS = ["fix", "fixes", "fixed", "close", "closes", "closed", "resolve", "resolves", "resolved"]; | ||
|
|
@@ -861,6 +869,33 @@ describe("safe_output_type_validator", () => { | |
| expect(result.isValid).toBe(false); | ||
| expect(result.error).toContain("too short"); | ||
| }); | ||
|
|
||
| it("should reject update_release body shorter than minLength (e.g. 'test')", async () => { | ||
| const { validateItem } = await import("./safe_output_type_validator.cjs"); | ||
|
|
||
| const result = validateItem({ type: "update_release", tag: "v1.0.0", operation: "prepend", body: "test" }, "update_release", 1); | ||
|
|
||
| expect(result.isValid).toBe(false); | ||
| expect(result.error).toContain("too short"); | ||
| expect(result.error).toContain("20"); | ||
| }); | ||
|
|
||
| it("should accept update_release body that meets minLength", async () => { | ||
| const { validateItem } = await import("./safe_output_type_validator.cjs"); | ||
|
|
||
| const result = validateItem({ type: "update_release", tag: "v1.0.0", operation: "prepend", body: "Patch release with bug fixes and improvements." }, "update_release", 1); | ||
|
|
||
| expect(result.isValid).toBe(true); | ||
| }); | ||
|
|
||
| it("should reject update_release body that is only whitespace below minLength", async () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] Misleading test name: the body value 💡 Suggested additionsRename the existing test to reflect what it actually covers: it("should reject update_release body whose trimmed length is below minLength (whitespace-padded)", async () => {And add a dedicated purely-whitespace test: it("should reject update_release body that is purely whitespace", async () => {
const { validateItem } = await import("./safe_output_type_validator.cjs");
const result = validateItem(
{ type: "update_release", tag: "v1.0.0", operation: "replace", body: " " },
"update_release", 1
);
expect(result.isValid).toBe(false);
expect(result.error).toContain("too short");
});This closes the gap between what the test name promises and what it actually verifies. |
||
| const { validateItem } = await import("./safe_output_type_validator.cjs"); | ||
|
|
||
| const result = validateItem({ type: "update_release", tag: "v1.0.0", operation: "prepend", body: " test " }, "update_release", 1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whitespace test uses wrong input — doesn't exercise the trim path at all. The test name promises coverage of "only whitespace below minLength", but 💡 What to test insteadThe dangerous case is content whose raw length meets the minLength threshold but whose trimmed length falls below it — e.g. 20+ spaces. The existing // create_issue's whitespace test — 25 spaces, raw length ≥ 20, trimmed → "" → rejected
validateItem({ ..., body: " " }, ...)The it("should reject update_release body that is only whitespace even when raw length meets minLength", async () => {
const { validateItem } = await import("./safe_output_type_validator.cjs");
// 20 spaces: passes JSON Schema minLength:20, but trim() → "" → runtime should reject it
const result = validateItem(
{ type: "update_release", tag: "v1.0.0", operation: "prepend", body: " " },
"update_release", 1
);
expect(result.isValid).toBe(false);
expect(result.error).toContain("too short");
});Without this, removing the |
||
|
|
||
|
Comment on lines
+891
to
+895
|
||
| expect(result.isValid).toBe(false); | ||
| expect(result.error).toContain("too short"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("array validation", () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd] All three new tests use
operation: "prepend". SinceminLengthenforces a floor regardless of operation, adding one test withoperation: "replace"(the most common case) would confirm the constraint is operation-agnostic and guard against any future per-operation branching in the validator.💡 Suggested addition