git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Consider escaping special characters like 'less' does

From
Jeff King <peff@peff.net>
Date
Oct 23, 2017, 00:45 UTC
Message-ID
<20171023004523.temglxnlpuns2ejy@sigill.intra.peff.net>
In-Reply-To
<37013BB09DFE493BB7E11E66A34657CE@blackfat>
On Sun, Oct 22, 2017 at 08:27:20AM -0400, Jason Pyeron wrote:
> > ESC (for color)
> > +			if ($line =~ s/[\000-\011\013-\032\034-\037]/?/g) {
> 
> What about CR [0x0D] ?

I assumed that CR was one of the things we'd want to avoid (and it was in fact what I used to test this). E.g., try:

  echo base >file
  git add file
  printf 'foo\r+bar\n' >file
Running through "less" shows something like:
  diff --git a/file b/file
  index df967b9..5b6ee80 100644
  --- a/file
  +++ b/file
  @@ -1 +1 @@
  -base
  +foo^M+bar
but "git add -p" shows:
  $ git add -p
  diff --git a/file b/file
  index df967b9..5b6ee80 100644
  --- a/file
  +++ b/file
  @@ -1 +1 @@
  -base
  +bar
  Stage this hunk [y,n,q,a,d,/,e,?]? 

For systems where CRLF is the native line ending, we'd still expect to see only LFs here when line-ending conversion is on (since the diff shows the canonical in-repo form).

For files where the CRs must remain for some reason, they'd show as a "?" at the end. The "^M" shown by "less" is a bit more informative. If we really do want to pursue this direction, it might make sense to use more descriptive placeholders.

-Peff
Previous: Jason Pyeron
Message 13 of 13 in “Consider escaping special characters like 'less' does”
  1. Joris ValetteOct 15, 2017
  2. Jason PyeronOct 15, 2017
  3. Andreas SchwabOct 15, 2017
  4. Joris ValetteOct 15, 2017
  5. Jeff KingOct 15, 2017
  6. Joris ValetteOct 15, 2017
  7. Jeff KingOct 16, 2017
  8. Andreas SchwabOct 16, 2017
  9. Jeff KingOct 16, 2017
  10. Junio C HamanoOct 17, 2017
  11. Jeff KingOct 17, 2017
  12. Jason PyeronOct 22, 2017
  13. Jeff KingOct 23, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.