[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: %q with truncating size loses safeness of %q

From: Robert Elz
Subject: Re: %q with truncating size loses safeness of %q
Date: Mon, 20 Apr 2020 04:33:49 +0700

    Date:        Sun, 19 Apr 2020 15:40:39 -0400
    From:        Chet Ramey <address@hidden>
    Message-ID:  <address@hidden>

  | Nobody, including POSIX, is rational, then.

There is no %q in POSIX printf currently, so the issue
does not arise there, and in any case, its objective is
not to be rational, but to document what works - and in
the existing implementations of printf %q (or the ones I
have seen) giving a precision for %q conversions doesn't
work in a rational way.

        printf %W.Pq arg

would be processed as

        printf %Ws $( quote $( printf %.Ps arg ) )

rather than as

        printf %W.Ps $( quote $( printf %s arg ) )

which is what we all do (the NetBSD printf doesn't have %q - I have
it implemented, but refuse to commit it because this is just so ugly,
and I'm much too lazy to do it properly).


ps: in the above, supply shell quoting as needed - I omitted it to
avoid quoting confusion...   and "W' and "P" stand for the (optional)
width and precision values (numbers, or '*').

reply via email to

[Prev in Thread] Current Thread [Next in Thread]