Repository navigation
Conversation
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>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 everygettextmessage between such literals — exactly the symptom in #640, where the message between/>/gand/'/gdisappears.A JS regexp literal cannot contain a line terminator, so dropping
DOTALLand excluding newlines from the character classes bounds a failed match to a single line. With the source from #640:['First message', 'Third message'](matches the report's POT output)['First message', 'Second message', 'Third message']The new
test_regexp_literal_cannot_span_linespins the tokenizer behaviour, andtest_regexp_literals_do_not_swallow_messagescovers 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 asif/elseso both parametrised cases stay visible in the report).Prior art: #791 rewrites this pattern to handle
/inside character classes, but it keepsDOTALL(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.