Skip to content

Feedback#1

Open
github-classroom[bot] wants to merge 388 commits into
feedbackfrom
main
Open

Feedback#1
github-classroom[bot] wants to merge 388 commits into
feedbackfrom
main

Conversation

@github-classroom
Copy link
Copy Markdown

@github-classroom github-classroom Bot commented May 12, 2025

👋! GitHub Classroom created this pull request as a place for your teacher to leave feedback on your work. It will update automatically. Don’t close or merge this pull request, unless you’re instructed to do so by your teacher.
In this pull request, your teacher can leave comments and feedback on your code. Click the Subscribe button to be notified if that happens.
Click the Files changed or Commits tab to see all of the changes pushed to the default branch since the assignment started. Your teacher can see this too.

Notes for teachers

Use this PR to leave feedback. Here are some tips:

  • Click the Files changed tab to see all of the changes pushed to the default branch since the assignment started. To leave comments on specific lines of code, put your cursor over a line of code and click the blue + (plus sign). To learn more about comments, read “Commenting on a pull request”.
  • Click the Commits tab to see the commits pushed to the default branch. Click a commit to see specific changes.
  • If you turned on autograding, then click the Checks tab to see the results.
  • This page is an overview. It shows commits, line comments, and general comments. You can leave a general comment below.
    For more information about this pull request, read “Leaving assignment feedback in GitHub”.

Subscribed: @arqii22 @Taniatos @hongjie94 @t1homas @ghoveybu @schin8

@ghoveybu ghoveybu temporarily deployed to my-magical-bedtime May 26, 2025 16:03 Inactive
@ghoveybu ghoveybu temporarily deployed to my-magical-bedtime May 26, 2025 22:15 Inactive
@netlify
Copy link
Copy Markdown

netlify Bot commented May 26, 2025

Deploy Preview for mymagicalbedtime ready!

Name Link
🔨 Latest commit dca9e60
🔍 Latest deploy log https://app.netlify.com/projects/mymagicalbedtime/deploys/6851923c12254b0008e3fdfd
😎 Deploy Preview https://deploy-preview-1--mymagicalbedtime.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ghoveybu ghoveybu temporarily deployed to my-magical-bedtime May 26, 2025 22:27 Inactive
@ghoveybu ghoveybu temporarily deployed to my-magical-bedtime May 26, 2025 22:29 Inactive
@ghoveybu ghoveybu temporarily deployed to my-magical-bedtime May 27, 2025 00:07 Inactive
@ghoveybu ghoveybu temporarily deployed to my-magical-bedtime May 27, 2025 01:34 Inactive
@netlify
Copy link
Copy Markdown

netlify Bot commented May 27, 2025

Deploy Preview for velvety-entremet-8ac832 canceled.

Name Link
🔨 Latest commit dca9e60
🔍 Latest deploy log https://app.netlify.com/projects/velvety-entremet-8ac832/deploys/6851923cb142a20008f7c46b

@hongjie94 hongjie94 had a problem deploying to magicalbedtimebackend May 27, 2025 01:35 Failure
@ghoveybu ghoveybu temporarily deployed to my-magical-bedtime May 27, 2025 04:21 Inactive
@hongjie94 hongjie94 had a problem deploying to magicalbedtimebackend May 27, 2025 04:22 Failure
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 15, 2025

File Coverage
All files 8%
controllers/settingController.js 0%
controllers/storyController.js 0%
controllers/userController.js 66%
models/GenerationRequestModel.js 0%
models/ParentalControlsModel.js 85%
models/StoryModel.js 0%
models/UserModel.js 19%
routes/setting.js 0%
routes/story.js 0%

Minimum allowed coverage is 75%

Generated by 🐒 cobertura-action against dca9e60

Comment thread code/backend/controllers/settingController.js Dismissed
Comment on lines +71 to +77
let cleanedResponse = storyResponse
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/\t/g, "\\t")
.replace(/\f/g, "\\f")
.replace(/\b/g, "\\b")
.replace(/\\/g, "\\\\")

Check failure

Code scanning / CodeQL

Double escaping or unescaping High

This replacement may double-escape '' characters from
here
.

Copilot Autofix

AI 12 months ago

To fix the issue, we need to ensure that the storyResponse string is sanitized without introducing double-escaping. The best approach is to use a well-tested library for JSON parsing and sanitization, such as json5 or safe-json-stringify, which can handle edge cases more robustly. Alternatively, we can simplify the cleaning process by removing redundant replacements and focusing on extracting valid JSON directly.

The fix involves:

  1. Removing the problematic replace chain starting on line 71.
  2. Using a more robust method to extract and parse JSON from storyResponse, ensuring that escaping is handled correctly.
  3. Adding comments to clarify the sanitization process and prevent future errors.

Suggested changeset 1
code/backend/controllers/storyController.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/code/backend/controllers/storyController.js b/code/backend/controllers/storyController.js
--- a/code/backend/controllers/storyController.js
+++ b/code/backend/controllers/storyController.js
@@ -70,16 +70,8 @@
           // Clean the JSON string before parsing
-          let cleanedResponse = storyResponse
-            .replace(/\n/g, "\\n")
-            .replace(/\r/g, "\\r")
-            .replace(/\t/g, "\\t")
-            .replace(/\f/g, "\\f")
-            .replace(/\b/g, "\\b")
-            .replace(/\\/g, "\\\\")
-            .replace(/"/g, '\\"');
+          // Attempt to extract JSON directly from the response
+          const jsonMatch = storyResponse.match(/\{[\s\S]*\}/);
+          let cleanedResponse = jsonMatch ? jsonMatch[0] : storyResponse;
 
-          // Alternative approach: try to extract JSON from the response
-          const jsonMatch = cleanedResponse.match(/\{[\s\S]*\}/);
-          if (jsonMatch) {
-            cleanedResponse = jsonMatch[0];
-          }
+          // Log the extracted JSON for debugging
+          console.log("Extracted JSON response:", cleanedResponse);
 
EOF
@@ -70,16 +70,8 @@
// Clean the JSON string before parsing
let cleanedResponse = storyResponse
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/\t/g, "\\t")
.replace(/\f/g, "\\f")
.replace(/\b/g, "\\b")
.replace(/\\/g, "\\\\")
.replace(/"/g, '\\"');
// Attempt to extract JSON directly from the response
const jsonMatch = storyResponse.match(/\{[\s\S]*\}/);
let cleanedResponse = jsonMatch ? jsonMatch[0] : storyResponse;

// Alternative approach: try to extract JSON from the response
const jsonMatch = cleanedResponse.match(/\{[\s\S]*\}/);
if (jsonMatch) {
cleanedResponse = jsonMatch[0];
}
// Log the extracted JSON for debugging
console.log("Extracted JSON response:", cleanedResponse);

Copilot is powered by AI and may make mistakes. Always verify output.
const startTime = Date.now();
const { imageDescription, storyId } = req.body;
const userId = req.user._id;
console.log(imageDescription, storyId);

Check failure

Code scanning / CodeQL

Use of externally-controlled format string High

Format string depends on a
user-provided value
.

Copilot Autofix

AI 12 months ago

To fix the issue, we will sanitize the untrusted input (imageDescription) before passing it to console.log. Specifically, we will use a format string with a %s specifier to ensure that the untrusted input is treated as a string, regardless of its content. This approach aligns with the recommendation provided in the background section.

The changes will be made to line 235 in the generateImage function. We will replace the current console.log statement with one that uses a format string and passes imageDescription as an argument.


Suggested changeset 1
code/backend/controllers/storyController.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/code/backend/controllers/storyController.js b/code/backend/controllers/storyController.js
--- a/code/backend/controllers/storyController.js
+++ b/code/backend/controllers/storyController.js
@@ -234,3 +234,3 @@
   const userId = req.user._id;
-  console.log(imageDescription, storyId);
+  console.log("Image description: %s, Story ID: %s", imageDescription, storyId);
   try {
EOF
@@ -234,3 +234,3 @@
const userId = req.user._id;
console.log(imageDescription, storyId);
console.log("Image description: %s, Story ID: %s", imageDescription, storyId);
try {
Copilot is powered by AI and may make mistakes. Always verify output.
revisedPrompt: imageResult.revisedPrompt,
};

await Story.findByIdAndUpdate(storyId, updates);

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.

Copilot Autofix

AI 12 months ago

To fix the issue, we need to ensure that the storyId value is validated before it is used in the findByIdAndUpdate query. Since MongoDB _id fields are typically ObjectIds, we can validate that storyId is a valid ObjectId. If it is not, we should return an error response to the user.

The best way to implement this fix is to use the mongoose.Types.ObjectId.isValid method, which checks whether a given value is a valid ObjectId. This ensures that only valid ObjectIds are passed to the query, mitigating the risk of NoSQL injection.


Suggested changeset 1
code/backend/controllers/storyController.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/code/backend/controllers/storyController.js b/code/backend/controllers/storyController.js
--- a/code/backend/controllers/storyController.js
+++ b/code/backend/controllers/storyController.js
@@ -1 +1,2 @@
+const mongoose = require("mongoose");
 const Story = require("../models/StoryModel");
@@ -233,2 +234,10 @@
   const { imageDescription, storyId } = req.body;
+
+  // Validate storyId
+  if (!mongoose.Types.ObjectId.isValid(storyId)) {
+    return res.status(400).json({
+      success: false,
+      error: "Invalid storyId",
+    });
+  }
   const userId = req.user._id;
EOF
@@ -1 +1,2 @@
const mongoose = require("mongoose");
const Story = require("../models/StoryModel");
@@ -233,2 +234,10 @@
const { imageDescription, storyId } = req.body;

// Validate storyId
if (!mongoose.Types.ObjectId.isValid(storyId)) {
return res.status(400).json({
success: false,
error: "Invalid storyId",
});
}
const userId = req.user._id;
Copilot is powered by AI and may make mistakes. Always verify output.
audioUrl: audioDownloadUrl,
};

await Story.findByIdAndUpdate(storyId, updates);

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.

Copilot Autofix

AI 12 months ago

To fix the issue, we need to ensure that the storyId value is properly validated before being used in the Story.findByIdAndUpdate query. The best approach is to check that storyId is a valid MongoDB ObjectId. This can be achieved using the mongoose.Types.ObjectId.isValid method, which ensures that the input is a valid ObjectId format.

Steps to implement the fix:

  1. Add a validation step for storyId using mongoose.Types.ObjectId.isValid.
  2. If storyId is invalid, return an appropriate error response to the user.
  3. Proceed with the database query only if storyId passes validation.

Suggested changeset 1
code/backend/controllers/storyController.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/code/backend/controllers/storyController.js b/code/backend/controllers/storyController.js
--- a/code/backend/controllers/storyController.js
+++ b/code/backend/controllers/storyController.js
@@ -1,2 +1,3 @@
 const Story = require("../models/StoryModel");
+const mongoose = require("mongoose");
 const parentalControls = require("../models/ParentalControlsModel");
@@ -298,2 +299,10 @@
 
+  // Validate storyId
+  if (!mongoose.Types.ObjectId.isValid(storyId)) {
+    return res.status(400).json({
+      success: false,
+      error: "Invalid storyId format",
+    });
+  }
+
   const userId = req.user._id;
EOF
@@ -1,2 +1,3 @@
const Story = require("../models/StoryModel");
const mongoose = require("mongoose");
const parentalControls = require("../models/ParentalControlsModel");
@@ -298,2 +299,10 @@

// Validate storyId
if (!mongoose.Types.ObjectId.isValid(storyId)) {
return res.status(400).json({
success: false,
error: "Invalid storyId format",
});
}

const userId = req.user._id;
Copilot is powered by AI and may make mistakes. Always verify output.
return (
text
// Remove or replace problematic punctuation
.replace(/'/g, "'") // Replace curly quotes with straight quotes

Check warning

Code scanning / CodeQL

Replacement of a substring with itself Medium

This replaces ''' with itself.

Copilot Autofix

AI 12 months ago

To fix the issue, the replacement operation should be updated to replace curly single quotes ( and ) with straight single quotes ('). This aligns with the apparent intent of the function to normalize text for audio generation. The corrected line will use a regular expression that matches both types of curly single quotes and replaces them with a straight single quote.


Suggested changeset 1
code/backend/services/openaiService.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/code/backend/services/openaiService.js b/code/backend/services/openaiService.js
--- a/code/backend/services/openaiService.js
+++ b/code/backend/services/openaiService.js
@@ -141,3 +141,3 @@
           // Remove or replace problematic punctuation
-          .replace(/'/g, "'") // Replace curly quotes with straight quotes
+          .replace(/[‘’]/g, "'") // Replace curly single quotes with straight single quotes
           .replace(/"/g, '"') // Replace curly quotes with straight quotes
EOF
@@ -141,3 +141,3 @@
// Remove or replace problematic punctuation
.replace(/'/g, "'") // Replace curly quotes with straight quotes
.replace(/[]/g, "'") // Replace curly single quotes with straight single quotes
.replace(/"/g, '"') // Replace curly quotes with straight quotes
Copilot is powered by AI and may make mistakes. Always verify output.
text
// Remove or replace problematic punctuation
.replace(/'/g, "'") // Replace curly quotes with straight quotes
.replace(/"/g, '"') // Replace curly quotes with straight quotes

Check warning

Code scanning / CodeQL

Replacement of a substring with itself Medium

This replaces '"' with itself.

Copilot Autofix

AI 12 months ago

To fix the issue, the .replace(/"/g, '"') operation should be updated to correctly normalize curly quotes ( and ) to straight quotes ("). This can be achieved by using a regular expression that matches curly quotes and replacing them with straight quotes. Specifically, the replacement string should be updated to '"', and the regular expression should be modified to match curly quotes.

The fix involves editing the cleanTextForAudio function in the code/backend/services/openaiService.js file. No new dependencies are required for this fix.


Suggested changeset 1
code/backend/services/openaiService.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/code/backend/services/openaiService.js b/code/backend/services/openaiService.js
--- a/code/backend/services/openaiService.js
+++ b/code/backend/services/openaiService.js
@@ -142,3 +142,3 @@
           .replace(/'/g, "'") // Replace curly quotes with straight quotes
-          .replace(/"/g, '"') // Replace curly quotes with straight quotes
+          .replace(/[“”]/g, '"') // Replace curly quotes with straight quotes
           .replace(/['']/g, "'") // Normalize apostrophes
EOF
@@ -142,3 +142,3 @@
.replace(/'/g, "'") // Replace curly quotes with straight quotes
.replace(/"/g, '"') // Replace curly quotes with straight quotes
.replace(/[]/g, '"') // Replace curly quotes with straight quotes
.replace(/['']/g, "'") // Normalize apostrophes
Copilot is powered by AI and may make mistakes. Always verify output.
.replace(/[""]/g, '"') // Normalize quotation marks

// Add pauses for better speech flow
.replace(/\. /g, ". ") // Ensure space after periods

Check warning

Code scanning / CodeQL

Replacement of a substring with itself Medium

This replaces '. ' with itself.

Copilot Autofix

AI 12 months ago

To fix the issue, the redundant replacement operation on line 148 should be removed. The replacement of . with itself does not serve any purpose and can be safely eliminated without affecting the functionality of the cleanTextForAudio function. This will simplify the code and improve readability.


Suggested changeset 1
code/backend/services/openaiService.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/code/backend/services/openaiService.js b/code/backend/services/openaiService.js
--- a/code/backend/services/openaiService.js
+++ b/code/backend/services/openaiService.js
@@ -147,3 +147,3 @@
           // Add pauses for better speech flow
-          .replace(/\. /g, ". ") // Ensure space after periods
+          // Ensure space after periods
           .replace(/\? /g, "? ") // Ensure space after question marks
EOF
@@ -147,3 +147,3 @@
// Add pauses for better speech flow
.replace(/\. /g, ". ") // Ensure space after periods
// Ensure space after periods
.replace(/\? /g, "? ") // Ensure space after question marks
Copilot is powered by AI and may make mistakes. Always verify output.

// Add pauses for better speech flow
.replace(/\. /g, ". ") // Ensure space after periods
.replace(/\? /g, "? ") // Ensure space after question marks

Check warning

Code scanning / CodeQL

Replacement of a substring with itself Medium

This replaces '? ' with itself.

Copilot Autofix

AI 12 months ago

To fix the issue, the redundant replacement operation /\? /g should be removed from the cleanTextForAudio function. This will eliminate unnecessary code and ensure that the function only performs meaningful transformations on the input text. No additional imports, methods, or definitions are required for this fix.


Suggested changeset 1
code/backend/services/openaiService.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/code/backend/services/openaiService.js b/code/backend/services/openaiService.js
--- a/code/backend/services/openaiService.js
+++ b/code/backend/services/openaiService.js
@@ -148,3 +148,2 @@
           .replace(/\. /g, ". ") // Ensure space after periods
-          .replace(/\? /g, "? ") // Ensure space after question marks
           .replace(/! /g, "! ") // Ensure space after exclamation marks
EOF
@@ -148,3 +148,2 @@
.replace(/\. /g, ". ") // Ensure space after periods
.replace(/\? /g, "? ") // Ensure space after question marks
.replace(/! /g, "! ") // Ensure space after exclamation marks
Copilot is powered by AI and may make mistakes. Always verify output.
// Add pauses for better speech flow
.replace(/\. /g, ". ") // Ensure space after periods
.replace(/\? /g, "? ") // Ensure space after question marks
.replace(/! /g, "! ") // Ensure space after exclamation marks

Check warning

Code scanning / CodeQL

Replacement of a substring with itself Medium

This replaces '! ' with itself.

Copilot Autofix

AI 12 months ago

To fix the issue, the redundant replacement operation on line 150 should be removed. This will eliminate the unnecessary code and ensure that the cleanTextForAudio function only performs meaningful transformations on the input text. No additional imports, methods, or definitions are required for this fix.

Suggested changeset 1
code/backend/services/openaiService.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/code/backend/services/openaiService.js b/code/backend/services/openaiService.js
--- a/code/backend/services/openaiService.js
+++ b/code/backend/services/openaiService.js
@@ -149,3 +149,2 @@
           .replace(/\? /g, "? ") // Ensure space after question marks
-          .replace(/! /g, "! ") // Ensure space after exclamation marks
 
EOF
@@ -149,3 +149,2 @@
.replace(/\? /g, "? ") // Ensure space after question marks
.replace(/! /g, "! ") // Ensure space after exclamation marks

Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants