python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.34k stars 448 forks source link

javascript extraction method gives unexpected results with escaped newlines #1056

Open oomsveta opened 11 months ago

oomsveta commented 11 months ago

Hello, the other day I noticed an inconsistent behavior between the python and javascript extraction methods:

>>> list(extract("javascript", BytesIO(b"_('hey\\\nlol')")))
[(1, 'hey\nlol', [], None)]
>>> list(extract("python",     BytesIO(b"_('hey\\\nlol')")))
[(1, 'heylol', [], None)]

(Notice the extra newline between "hey" and "lol" with the javascript extraction method).

I think it's most likely a bug, and the JavaScript should behave the same as the Python. This is especially bad since the current behavior also differs from how the JavaScript parser interprets it:

const hey = _("hey \
lol"
);

The content of the variable is heylol, but the extracted source term is hey\nlol. The mismatch between the two will prevent the string from being translated by gettext at all.

Could you take a look? Thanks in advance!