Skip to content

Commit

Permalink
fix(codeChecker/validate.ts): regex lastIndex issue by creating a n…
Browse files Browse the repository at this point in the history
…ew instance.

- creates a new regex instance each time to fix lastIndex issues with the global flag, ensuring consistent matching in canvas validation.
  • Loading branch information
hassnian committed Oct 29, 2024
1 parent a47abc7 commit 49c6e5e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/codeChecker/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const constants = {
const validateCanvasCreation = (
sketchFileContent: string,
): Result<RegExpExecArray> => {
const canvasMatch = constants.canvasRegex.exec(sketchFileContent)
// Create a new regex instance to avoid issues with lastIndex when using the global flag.
const canvasMatch = new RegExp(constants.canvasRegex).exec(sketchFileContent)
if (!canvasMatch) {
return { isSuccess: false, error: 'createCanvas function not found.' }
}
Expand Down

0 comments on commit 49c6e5e

Please sign in to comment.