Potential fix for code scanning alert no. 6: Incomplete string escaping or encoding

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
Manan
2025-12-22 22:32:57 -08:00
committed by GitHub
parent 1b853a803d
commit 4be60d6218

View File

@@ -597,8 +597,11 @@ export async function init(
if (fs.existsSync(constantsPath)) { if (fs.existsSync(constantsPath)) {
let constantsContent = fs.readFileSync(constantsPath, 'utf8'); let constantsContent = fs.readFileSync(constantsPath, 'utf8');
// Helper function to escape single quotes in strings // Helper function to escape backslashes and single quotes in strings
const escapeString = (str) => str.replace(/'/g, "\\'"); const escapeString = (str) =>
String(str)
.replace(/\\/g, '\\\\') // escape all backslashes
.replace(/'/g, "\\'"); // then escape single quotes
// Helper function to safely replace constants with validation // Helper function to safely replace constants with validation
const safeReplace = (content, pattern, replacement, constantName) => { const safeReplace = (content, pattern, replacement, constantName) => {