]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
gettext, ngettext: Fix the expansion of '\\' and octal escape sequences.
authorBruno Haible <bruno@clisp.org>
Mon, 19 Aug 2019 00:16:43 +0000 (02:16 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 13 Apr 2020 11:08:01 +0000 (13:08 +0200)
* gettext-runtime/src/gettext.c (expand_escape): Don't swallow the expansion
of '\\' and octal escape sequences.
* gettext-runtime/src/ngettext.c (expand_escape): Likewise.
* gettext-tools/tests/tstgettext.c (expand_escape): Likewise.
* NEWS: Mention the change.

NEWS
gettext-runtime/src/gettext.c
gettext-runtime/src/ngettext.c
gettext-tools/tests/tstgettext.c

diff --git a/NEWS b/NEWS
index 8913a61a365bede3db9592233ef678e715c49d50..a80d9c8eeca5a729115443a31e675e717a42ed13 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,10 @@
 Version 0.20.2 - April 2020
 
 * Programming languages support:
+  - Shell:
+    The programs 'gettext', 'ngettext', when invoked with option -e, now
+    expand '\\' and octal escape sequences, instead of swallowing them.
+    (Bug present since the beginning.)
   - Desktop Entry:
     The value of the 'Icon' property is no longer extracted into the POT file
     by xgettext.  The documentation explains how to localize icons.
index e2fe24a2b6df4c780bcd4ed29a9a3d5c98011671..ac50ad4c777f885b73c23c7f4b29d21cfa0b0912 100644 (file)
@@ -316,6 +316,8 @@ expand_escape (const char *str)
   char *retval, *rp;
   const char *cp = str;
 
+  /* Find the location of the first escape sequence.
+     If the string contains no escape sequences, return it right away.  */
   for (;;)
     {
       while (cp[0] != '\0' && cp[0] != '\\')
@@ -373,7 +375,7 @@ expand_escape (const char *str)
           ++cp;
           break;
         case '\\':
-          *rp = '\\';
+          *rp++ = '\\';
           ++cp;
           break;
         case '0': case '1': case '2': case '3':
@@ -392,21 +394,22 @@ expand_escape (const char *str)
                     ch += *cp++ - '0';
                   }
               }
-            *rp = ch;
+            *rp++ = ch;
           }
           break;
         default:
-          *rp = '\\';
+          *rp++ = '\\';
           break;
         }
 
+      /* Find the next escape sequence.  */
       while (cp[0] != '\0' && cp[0] != '\\')
         *rp++ = *cp++;
     }
   while (cp[0] != '\0');
 
-  /* Terminate string.  */
+  /* Terminate the resulting string.  */
   *rp = '\0';
 
-  return (const char *) retval;
+  return retval;
 }
index 1e853d091a1107dfbc33ca1307ba87258d87a713..685bf7fbbdefd260c15b4868b8a7c7594a572056 100644 (file)
@@ -279,6 +279,8 @@ expand_escape (const char *str)
   char *retval, *rp;
   const char *cp = str;
 
+  /* Find the location of the first escape sequence.
+     If the string contains no escape sequences, return it right away.  */
   for (;;)
     {
       while (cp[0] != '\0' && cp[0] != '\\')
@@ -332,7 +334,7 @@ expand_escape (const char *str)
           ++cp;
           break;
         case '\\':
-          *rp = '\\';
+          *rp++ = '\\';
           ++cp;
           break;
         case '0': case '1': case '2': case '3':
@@ -351,21 +353,22 @@ expand_escape (const char *str)
                     ch += *cp++ - '0';
                   }
               }
-            *rp = ch;
+            *rp++ = ch;
           }
           break;
         default:
-          *rp = '\\';
+          *rp++ = '\\';
           break;
         }
 
+      /* Find the next escape sequence.  */
       while (cp[0] != '\0' && cp[0] != '\\')
         *rp++ = *cp++;
     }
   while (cp[0] != '\0');
 
-  /* Terminate string.  */
+  /* Terminate the resulting string.  */
   *rp = '\0';
 
-  return (const char *) retval;
+  return retval;
 }
index 480dda42266a0cb36fa39622846adf35d4d0c019..48fb92a5d5154292fd17b522876a9010d025b0c2 100644 (file)
@@ -317,6 +317,8 @@ expand_escape (const char *str)
   char *retval, *rp;
   const char *cp = str;
 
+  /* Find the location of the first escape sequence.
+     If the string contains no escape sequences, return it right away.  */
   for (;;)
     {
       while (cp[0] != '\0' && cp[0] != '\\')
@@ -374,7 +376,7 @@ expand_escape (const char *str)
           ++cp;
           break;
         case '\\':
-          *rp = '\\';
+          *rp++ = '\\';
           ++cp;
           break;
         case '0': case '1': case '2': case '3':
@@ -393,21 +395,22 @@ expand_escape (const char *str)
                     ch += *cp++ - '0';
                   }
               }
-            *rp = ch;
+            *rp++ = ch;
           }
           break;
         default:
-          *rp = '\\';
+          *rp++ = '\\';
           break;
         }
 
+      /* Find the next escape sequence.  */
       while (cp[0] != '\0' && cp[0] != '\\')
         *rp++ = *cp++;
     }
   while (cp[0] != '\0');
 
-  /* Terminate string.  */
+  /* Terminate the resulting string.  */
   *rp = '\0';
 
-  return (const char *) retval;
+  return retval;
 }