From ecb5f6d70f376d59250c6976bb31be9a9b4a26eb Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Mon, 1 Sep 2025 08:51:32 -0600 Subject: [PATCH] error checking update --- .../local/parsingTests/assignmentHtml.test.ts | 43 +++++++++++++++++++ src/services/htmlMarkdownUtils.ts | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/features/local/parsingTests/assignmentHtml.test.ts b/src/features/local/parsingTests/assignmentHtml.test.ts index 789d1dd..a4e83a9 100644 --- a/src/features/local/parsingTests/assignmentHtml.test.ts +++ b/src/features/local/parsingTests/assignmentHtml.test.ts @@ -40,10 +40,53 @@ describe("AssignmentHtmlTest", () => { { source: "insert_github_classroom_url", destination: "findme", + strict: true, }, ], }); expect(html).toContain(`href="findme"`); }); + + it("assignment without text in description does not throw error", () => { + const name = "test assignment"; + const assignment: LocalAssignment = { + name, + description: `here is the description without a classroom url`, + dueAt: "08/21/2023 23:59:00", + lockAt: "08/21/2023 23:59:00", + submissionTypes: [AssignmentSubmissionType.ONLINE_UPLOAD], + localAssignmentGroupName: "Final Project", + rubric: [], + allowedFileUploadExtensions: [], + githubClassroomAssignmentShareLink: "findme", + }; + const settings: LocalCourseSettings = { + name: "test empty course", + assignmentGroups: [], + daysOfWeek: [DayOfWeek.Monday, DayOfWeek.Wednesday], + startDate: "07/09/2024 23:59:00", + endDate: "07/09/2024 23:59:00", + defaultDueTime: { hour: 1, minute: 59 }, + canvasId: 0, + defaultAssignmentSubmissionTypes: [], + defaultFileUploadTypes: [], + holidays: [], + assets: [], + }; + expect(() => { + markdownToHTMLSafe({ + markdownString: assignment.description, + settings, + convertImages: false, + replaceText: [ + { + source: "insert_github_classroom_url", + destination: "shouldn't be here", + strict: true, + }, + ], + }); + }).not.toThrow(); + }); }); diff --git a/src/services/htmlMarkdownUtils.ts b/src/services/htmlMarkdownUtils.ts index fc414aa..59b48d2 100644 --- a/src/services/htmlMarkdownUtils.ts +++ b/src/services/htmlMarkdownUtils.ts @@ -92,7 +92,7 @@ export function markdownToHTMLSafe({ const html = markdownToHtmlNoImages(markdownString); const replacedHtml = replaceText.reduce( (acc, { source, destination, strict = false }) => { - if (strict) { + if (strict && acc.includes(source)) { if (typeof destination === "undefined" || destination === null) { throw new Error( `Text replacement failed: destination is undefined for source "${source}"`