Pádraig Brady wrote:
> > If a string starts with a sequence that requires $'' quoting followed
> > by a \' and then another charactrer requiring $'' quoting, the '$' at
> > the start of the quoted string ends up missing:
> > 
> >      $ env printf '%q\n' $'\1\'\2'
> >      '\001'\'''$'\002'
> 
> Indeed that is a bug.
> I'll be able to have a look at this tomorrow.

The '$' at the beginning is only missing in specific cases:

$ ./printf '%q\n' $'\1\'\2'
'\001'\'''$'\002'
$ ./printf '%q\n' $'a\1\'\2'
'''a'$'\001'\'''$'\002'
$ ./printf '%q\n' $'\1\'\2x'
''$'\001'\'''$'\002''x'

Also, let me apply some documentation improvement to the .h file (attached).

Bruno

>From 4d694d878f8792d510f5d30eaaf9d51c7b48ca10 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 31 Mar 2024 22:56:14 +0200
Subject: [PATCH] quotearg: Improve documentation.

* lib/quotearg.h: Refer to specification of $'...' syntax. Document a
limitation of QA_ELIDE_OUTER_QUOTES.
---
 ChangeLog      |  6 ++++++
 lib/quotearg.h | 12 +++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ffae5513ae..182a894039 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-03-31  Bruno Haible  <br...@clisp.org>
+
+	quotearg: Improve documentation.
+	* lib/quotearg.h: Refer to specification of $'...' syntax. Document a
+	limitation of QA_ELIDE_OUTER_QUOTES.
+
 2024-03-31  Bruno Haible  <br...@clisp.org>
 
 	canonicalize[-lgpl] tests: Fix test failure on musl libc.
diff --git a/lib/quotearg.h b/lib/quotearg.h
index 4e9099fff4..202b79f33e 100644
--- a/lib/quotearg.h
+++ b/lib/quotearg.h
@@ -80,7 +80,8 @@ enum quoting_style
 
     /* Quote names for the shell if they contain shell metacharacters
        or other problematic characters (ls --quoting-style=shell-escape).
-       Non printable characters are quoted using the $'...' syntax,
+       Non printable characters are quoted using the $'...' syntax
+       <https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html>,
        which originated in ksh93 and is widely supported by most shells,
        and proposed for inclusion in POSIX.
 
@@ -95,7 +96,8 @@ enum quoting_style
 
     /* Quote names for the shell even if they would normally not
        require quoting (ls --quoting-style=shell-escape).
-       Non printable characters are quoted using the $'...' syntax,
+       Non printable characters are quoted using the $'...' syntax
+       <https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html>,
        which originated in ksh93 and is widely supported by most shells,
        and proposed for inclusion in POSIX.  Behaves like
        shell_escape_quoting_style if QA_ELIDE_OUTER_QUOTES is in effect.
@@ -253,7 +255,11 @@ enum quoting_flags
 
     /* Omit the surrounding quote characters if no escaped characters
        are encountered.  Note that if no other character needs
-       escaping, then neither does the escape character.  */
+       escaping, then neither does the escape character.
+       *Attention!*  This flag is unsupported in combination with the styles
+       shell_escape_quoting_style and shell_escape_always_quoting_style
+       (because in this situation it cannot handle strings that start
+       with a non-printable character).  */
     QA_ELIDE_OUTER_QUOTES = 0x02,
 
     /* In the c_quoting_style and c_maybe_quoting_style, split ANSI
-- 
2.34.1

Reply via email to