]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Fix parsing of XML tags that end in /> and have attributes.
authorBruno Haible <bruno@clisp.org>
Sun, 29 Sep 2019 12:29:41 +0000 (14:29 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 13 Apr 2020 11:20:32 +0000 (13:20 +0200)
Reported by Matej Marusak <marusak.matej@gmail.com>
in <https://savannah.gnu.org/bugs/?56848>.

* 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.

gettext-tools/src/x-javascript.c
gettext-tools/tests/xgettext-javascript-6

index 020ba988d9b79404271aa7056245ce3bf656a50f..b34d92eaa5f0820c480064cf638184ffc642350c 100644 (file)
@@ -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);
                 }
index 375e377930c3d539afad967a7d6fd10c7eba1689..ec2cbddd6fc0d84fbb114923c664cd3f232c5ec4 100755 (executable)
@@ -4,6 +4,24 @@
 # Test of JavaScript E4X support.
 
 cat <<\EOF > xg-js-6.js
+class Foo extends React.Component {
+    render() {
+        return (
+            <div className="aClass" />
+        );
+    }
+}
+class Bar extends React.Component {
+    render() {
+        return (
+            <div>
+                <span className="someClass" />
+                { gettext('Expected translation string #0') }
+            </div>
+        );
+    }
+}
+
 var x1 = <x1></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 ""