Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/server/trmnl/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { verifyAccessToken } from '@/server/trmnl/token.ts';
import { fetchAssignmentData } from '@/server/utilities/fetchAssignmentData.ts';
import {
createRequestLogger,
performSafeContextBodyParse,
performSafeContextFormBodyParse,
} from '@/server/utilities/honoUtilities.ts';
import { stringifyError, tryCatch } from '@/shared/utilities/tryCatch.ts';

Expand Down Expand Up @@ -50,7 +50,7 @@ export const generate = async (c: Context) => {
}

// Parse the body as application/x-www-form-urlencoded
const [formSuccess, form] = await performSafeContextBodyParse(c);
const [formSuccess, form] = await performSafeContextFormBodyParse(c);
if (!formSuccess) {
logger.info('Invalid form body.');
return c.text('Invalid form body.', 400);
Expand Down
14 changes: 10 additions & 4 deletions src/server/utilities/honoUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ export const performSafeContextJsonParse = async (
}
};

export const performSafeContextBodyParse = async (
export const performSafeContextFormBodyParse = async (
c: Context,
): Promise<[true, unknown] | [false, undefined]> => {
): Promise<[true, Record<string, string>] | [false, undefined]> => {
try {
const body = await c.req.parseBody();
return [true, body];
const body = await c.req.text();
// Pase x-www-form-urlencoded body
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typo in comment.

"Pase" should be "Parse".

Apply this diff:

-        // Pase x-www-form-urlencoded body
+        // Parse x-www-form-urlencoded body
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Pase x-www-form-urlencoded body
// Parse x-www-form-urlencoded body
🤖 Prompt for AI Agents
In src/server/utilities/honoUtilities.ts around line 22, fix the typo in the
inline comment: change "Pase x-www-form-urlencoded body" to "Parse
x-www-form-urlencoded body".

const params = new URLSearchParams(body);
const bodyObject: Map<string, string> = new Map();
params.forEach((value, key) => {
bodyObject.set(key, value);
});
return [true, Object.fromEntries(bodyObject)];
} catch (_error) {
return [false, undefined];
}
Expand Down
Loading