From: Jeff King <peff@peff.net>
To: Yaakov Smith <Yaakov.Smith@wisetechglobal.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: \b character escapes in CLI usage
Date: Wed, 26 Feb 2025 02:38:22 -0500 [thread overview]
Message-ID: <20250226073822.GA21138@coredump.intra.peff.net> (raw)
In-Reply-To: <SYBPR01MB579278DD5EC6E13CA9A213FDE2C32@SYBPR01MB5792.ausprd01.prod.outlook.com>
On Tue, Feb 25, 2025 at 11:44:33PM +0000, Yaakov Smith wrote:
> In some places, such as trying to fetch a remote with this in the URL, git will render the character differently.
>
> [remote "backslashb"]
> url = "\b"
> fetch = +refs/heads/*:refs/remotes/backslashb/*
>
> $ git fetch backslashb
> fatal: '?' does not appear to be a git repository
> fatal: Could not read from remote repository.
Here we sanitize error output, because we know the result is human
readable (and likely to be showing untrusted input from the repo or a
remote server).
> When using "git config --list" however, this is emitted in its raw format, and can be used to mask or hide an actual (probably invalid) value:
>
> $ cat .git/config
> [core]
> somevalue = "true\b\b\b\bfalse"
> $ git config --local --list
> core.somevalue=false
But here, the point of "git config" is to show the output. If we
sanitized it (especially in a lossy way like we do for error messages),
then any program reading the output would not see the real data.
> Should "git config" be smarter here and print something other than a
> literal backspace to the terminal, like "git fetch" does?
So I would say no here, in general.
We could perhaps try to be kinder about sanitizing output when it is
going to a terminal, rather than a pipe. But quite curiously, that
should already be the case for "config --list"! It invokes a pager by
default. Much to my surprise, though, "less" does not seem to treat
backspace as a control character. It can be configured to do so:
$ LESS=FRXU git config --list --local
...
core.foo=true^H^H^H^Hfalse
Here's what the manpage for less(1) says:
By default, if neither -u nor -U is given, backspaces which appear
adjacent to an underscore character are treated specially: the
underlined text is displayed using the terminal's hardware underlining
capability. Also, backspaces which appear between two identical
characters are treated specially: the overstruck text is printed using
the terminal's hardware boldface capability. Other backspaces are
deleted, along with the preceding character.[...]
So I guess it is intentional to allow programs to use some effects, but
in general I think I might prefer them being marked visually. Especially
because the same would be true in a diff, like:
git init
echo old >file && git add file && git commit -m old
printf 'sneaky\b\b\b\b\bnew\n' >file && git commit -m new
git show
which respects the backspaces (actually it says "snew" with a bolded "n"
because of the overstrike rule ;) ).
I wonder if we should consider adding "U" to the default $LESS variable
we set.
-Peff
next prev parent reply other threads:[~2025-02-26 7:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-25 23:44 \b character escapes in CLI usage Yaakov Smith
2025-02-26 7:38 ` Jeff King [this message]
2025-02-26 8:09 ` Jeff King
2025-02-26 16:02 ` Junio C Hamano
2025-02-26 16:38 ` Kyle Lippincott
2025-02-26 22:06 ` Jeff King
2025-02-26 15:59 ` Junio C Hamano
2025-02-26 23:36 ` brian m. carlson
2025-02-26 23:55 ` Junio C Hamano
2025-02-27 0:03 ` Junio C Hamano
2025-02-27 14:06 ` General output formatting (was: Re: \b character escapes in CLI usage) Marc Branchaud
2025-02-27 17:06 ` General output formatting Junio C Hamano
2025-02-27 17:14 ` Marc Branchaud
2025-02-27 18:40 ` Junio C Hamano
2025-02-27 16:26 ` \b character escapes in CLI usage Phillip Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250226073822.GA21138@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=Yaakov.Smith@wisetechglobal.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox