From: Bruno Haible Date: Sun, 29 Sep 2019 12:29:41 +0000 (+0200) Subject: xgettext: Fix parsing of XML tags that end in /> and have attributes. X-Git-Tag: v0.20.2~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96af7be989a1bc5b2ac3d17b0992a0a69179cee4;p=thirdparty%2Fgettext.git xgettext: Fix parsing of XML tags that end in /> and have attributes. Reported by Matej Marusak in . * gettext-tools/src/x-javascript.c (phase5_get): After reading a string, reset the lexical_context to the previous one, not to lc_outside. When reading /> at the end of an XML element, decrement xml_element_depth. * gettext-tools/tests/xgettext-javascript-6: Add a test. --- diff --git a/gettext-tools/src/x-javascript.c b/gettext-tools/src/x-javascript.c index 020ba988d..b34d92eaa 100644 --- a/gettext-tools/src/x-javascript.c +++ b/gettext-tools/src/x-javascript.c @@ -1181,10 +1181,10 @@ phase5_get (token_ty *tp) case '"': case '\'': /* Strings. */ { - int quote_char; + int quote_char = c; + lexical_context_ty saved_lexical_context = lexical_context; struct mixed_string_buffer msb; - quote_char = c; lexical_context = lc_string; /* Start accumulating the string. */ mixed_string_buffer_init (&msb, lexical_context, @@ -1211,7 +1211,7 @@ phase5_get (token_ty *tp) } tp->mixed_string = mixed_string_buffer_result (&msb); tp->comment = add_reference (savable_comment); - lexical_context = lc_outside; + lexical_context = saved_lexical_context; tp->type = last_token_type = token_type_string; return; } @@ -1349,7 +1349,12 @@ phase5_get (token_ty *tp) { c = phase2_getc (); if (c == '>') - lexical_context = lc_outside; + { + if (xml_element_depth-- > 0) + lexical_context = lc_xml_content; + else + lexical_context = lc_outside; + } else phase2_ungetc (c); } diff --git a/gettext-tools/tests/xgettext-javascript-6 b/gettext-tools/tests/xgettext-javascript-6 index 375e37793..ec2cbddd6 100755 --- a/gettext-tools/tests/xgettext-javascript-6 +++ b/gettext-tools/tests/xgettext-javascript-6 @@ -4,6 +4,24 @@ # Test of JavaScript E4X support. cat <<\EOF > xg-js-6.js +class Foo extends React.Component { + render() { + return ( +
+ ); + } +} +class Bar extends React.Component { + render() { + return ( +
+ + { gettext('Expected translation string #0') } +
+ ); + } +} + var x1 = ; var s1 = _("Expected translation string #1"); var s2 = "foo"; @@ -54,6 +72,9 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" +msgid "Expected translation string #0" +msgstr "" + msgid "Expected translation string #1" msgstr ""