Skip to content

Conversation

@Alimadcorp
Copy link
Collaborator

No description provided.

@vercel
Copy link

vercel bot commented Jan 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
note-plus ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 25, 2025 7:16pm


const wordBoundary = wholeWordCheckbox.checked ? "\\b" : "";
const regex = new RegExp(
`${wordBoundary}${oldWord.replace(/\//g, "\\/")}${wordBoundary}`,

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.

Copilot Autofix

AI 11 months ago

To fix the problem, we need to ensure that backslashes in oldWord are properly escaped before using it in a regular expression. This can be done by adding a replace call to escape backslashes before escaping forward slashes. This ensures that all occurrences of backslashes are correctly handled.

We will modify the line where oldWord is processed to escape backslashes first, followed by forward slashes. This change will be made in the replaceWord function.

Suggested changeset 1
public/js/search.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/public/js/search.js b/public/js/search.js
--- a/public/js/search.js
+++ b/public/js/search.js
@@ -105,3 +105,3 @@
   const regex = new RegExp(
-    `${wordBoundary}${oldWord.replace(/\//g, "\\/")}${wordBoundary}`,
+    `${wordBoundary}${oldWord.replace(/\\/g, "\\\\").replace(/\//g, "\\/")}${wordBoundary}`,
     flags
EOF
@@ -105,3 +105,3 @@
const regex = new RegExp(
`${wordBoundary}${oldWord.replace(/\//g, "\\/")}${wordBoundary}`,
`${wordBoundary}${oldWord.replace(/\\/g, "\\\\").replace(/\//g, "\\/")}${wordBoundary}`,
flags
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.

2 participants