From b05c561bbf1147deb9fbeda2a685d5f7a4a927da Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 10 Mar 2025 17:02:12 -0400
Subject: fixed labels to work with words that have apostrophes.

---
 src/client/views/StyleProviderQuiz.tsx | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

(limited to 'src/client/views/StyleProviderQuiz.tsx')

diff --git a/src/client/views/StyleProviderQuiz.tsx b/src/client/views/StyleProviderQuiz.tsx
index 4e845f9f5..76fd3baa2 100644
--- a/src/client/views/StyleProviderQuiz.tsx
+++ b/src/client/views/StyleProviderQuiz.tsx
@@ -46,7 +46,7 @@ export namespace styleProviderQuiz {
      * @param boxes
      * @param texts
      */
-    async function createBoxes(img: ImageBox, boxes: [[[number, number]]], texts: [string]) {
+    async function createBoxes(img: ImageBox, boxes: number[][][], texts: string[]) {
         img.Document.quizBoxes = new List<Doc>([]);
         for (let i = 0; i < boxes.length; i++) {
             const coords = boxes[i] ? boxes[i] : [];
@@ -87,9 +87,10 @@ export namespace styleProviderQuiz {
             runInAction(() => (imgBox.Loading = true));
 
             const response = (await Networking.PostToServer('/labels', { file: i ? i : imgBox.paths[0], drag: i ? 'drag' : 'full', smart: quiz })) as { result: string };
-            const parsedResponse = JSON.parse(response.result.replace(/'/g, '"'));
-            if (parsedResponse['boxes'].length != 0) {
-                createBoxes(imgBox, parsedResponse['boxes'], parsedResponse['text']);
+            const replacedResponse = response.result.replace(/ '/g, '"').replace(/',/g, '",').replace(/\{'/g, '{"').replace(/':/g, '":').replace(/'\]/g, '"]').replace(/\[']/g, '["');
+            const parsedResponse = JSON.parse(replacedResponse) as { boxes: number[][][]; text: string[] };
+            if (parsedResponse.boxes.length != 0) {
+                createBoxes(imgBox, parsedResponse.boxes, parsedResponse.text);
             }
             runInAction(() => (imgBox.Loading = false));
         } else quizBoxes.forEach(box => (box.hidden = false));
-- 
cgit v1.2.3-70-g09d2

