Incorrect regex in javascript text generator
Author: rachel-fenichelCreated Nov 30, 2021Updated Sep 28, 2026
Labelshelp wantedgood first issuearea: generators
Describe the bug
The strRegExp in generators/javascript/text.js and generators/python/text.js (and possibly others) is supposed to match valid single-quoted string literals, but it matches some strings which are not valid literals.
To Reproduce
Try matching the strings'C:\\\', which is not a valid string literal (no closing single-quote):
const strRegExp = /^\s*'([^']|\\')*'\s*$/;
strRegExp.test("'C:\\\\\\'"); // Should be false, but returns trueAdditional context
For JavaScript, consider cribbing regexps.singleQuotedString from google/CodeCity/server/code.js.
Originally mentiond by @cpcallen in https://github.com/google/blockly/pull/5750#discussion_r759615764
Source: RaspberryPiFoundation/blockly