From 523a05d45eda14712533db2b633bf27d88889328 Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Fri, 29 Aug 2025 11:05:50 -0600 Subject: [PATCH] when creating assignments, verify the classroom url can be swapped --- globalSettings.yml | 2 ++ .../canvas/services/canvasAssignmentService.ts | 2 ++ src/services/htmlMarkdownUtils.ts | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/globalSettings.yml b/globalSettings.yml index 831ebaf..a2decf9 100644 --- a/globalSettings.yml +++ b/globalSettings.yml @@ -17,3 +17,5 @@ courses: name: Old Adv Frontend - path: ./1430/2025-spring-jonathan/Modules/ name: Jonathan UX + - path: ./1400/2025_spring_alex/modules/ + name: 1400-spring diff --git a/src/features/canvas/services/canvasAssignmentService.ts b/src/features/canvas/services/canvasAssignmentService.ts index d40ca1b..fb7287a 100644 --- a/src/features/canvas/services/canvasAssignmentService.ts +++ b/src/features/canvas/services/canvasAssignmentService.ts @@ -36,6 +36,7 @@ export const canvasAssignmentService = { { source: "insert_github_classroom_url", destination: localAssignment.githubClassroomAssignmentShareLink || "", + strict: true, }, ], }); @@ -93,6 +94,7 @@ export const canvasAssignmentService = { source: "insert_github_classroom_url", destination: localAssignment.githubClassroomAssignmentShareLink || "", + strict: true, }, ], }), diff --git a/src/services/htmlMarkdownUtils.ts b/src/services/htmlMarkdownUtils.ts index ee9a337..fc414aa 100644 --- a/src/services/htmlMarkdownUtils.ts +++ b/src/services/htmlMarkdownUtils.ts @@ -87,11 +87,25 @@ export function markdownToHTMLSafe({ markdownString: string; settings: LocalCourseSettings; convertImages?: boolean; - replaceText?: { source: string; destination: string }[]; + replaceText?: { source: string; destination: string; strict?: boolean }[]; }) { const html = markdownToHtmlNoImages(markdownString); const replacedHtml = replaceText.reduce( - (acc, { source, destination }) => acc.replaceAll(source, destination), + (acc, { source, destination, strict = false }) => { + if (strict) { + if (typeof destination === "undefined" || destination === null) { + throw new Error( + `Text replacement failed: destination is undefined for source "${source}"` + ); + } + if (destination === "") { + throw new Error( + `Text replacement failed: destination is empty string for source "${source}"` + ); + } + } + return acc.replaceAll(source, destination); + }, html );