| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The tokenizer matched a JS regexp literal with re.DOTALL, so an unterminated match could run past line terminators and swallow the rest of the file. A literal like /'/ inside a ternary made extract_javascript drop every gettext message that followed it (issue python-babel#640). A JS regexp literal cannot contain a line terminator, so drop DOTALL and exclude newlines from the character classes instead. This restores extraction of the messages after such a literal; test_jsx_extraction now expects the same messages with and without the jsx option. Signed-off-by: simpleqt <2015900818@qq.com>
|
A small line-terminator test, if it's useful. The LF cases pass with this change, but the regexp rule still matches across CR, U+2028 and U+2029, including immediately after a backslash. The test covers all four terminators plus a normal-regexp control. On Windows/Python 3.14.4, six cases still fail on this head; both LF cases and the control pass. The full Babel/CLDR suite wasn't run. Would you consider excluding those other ECMAScript line terminators from both the ordinary and backslash paths too? |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fix jslexer regexp literals spanning lines (issue #640)
The tokenizer matched a JS regexp literal with re.DOTALL, so a match attempt could run past line terminators and swallow everything up to the next / on a later line. That silently dropped every gettext message between such literals — exactly the symptom in #640, where the message between />/g and /'/g disappears.
A JS regexp literal cannot contain a line terminator, so dropping DOTALL and excluding newlines from the character classes bounds a failed match to a single line. With the source from #640:
The new test_regexp_literal_cannot_span_lines pins the tokenizer behaviour, and test_regexp_literals_do_not_swallow_messages covers both regexp shapes from #640 at the extraction level.
One existing assertion changes meaning: test_jsx_extraction's source also contains regexp literals, and the buggy lexer dropped messages from it in non-JSX mode, which is what the old != assertion was locking in. With extraction fixed, non-JSX now yields the same messages as JSX, so the assertion becomes == (kept as if/else so both parametrised cases stay visible in the report).
Prior art: #791 rewrites this pattern to handle / inside character classes, but it keeps DOTALL (its character classes also match newlines), so it does not address the newline case in #640. The two fixes are independent; mine only changes newline handling.
I used an AI assistant (ZCode) to help locate the swallowing behavior in the tokenizer and to draft the tests; I verified the before/after behavior above myself and wrote the fix.