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

RE: Consider escaping special characters like 'less' does

From
Jason Pyeron <jpyeron@pdinc.us>
Date
Oct 22, 2017, 12:27 UTC
Message-ID
<37013BB09DFE493BB7E11E66A34657CE@blackfat>
In-Reply-To
<20171016221324.stn56gqnliunvcdv@sigill.intra.peff.net>
Show 7 quoted lines
> -----Original Message-----
> From: Jeff King
> Sent: Monday, October 16, 2017 6:13 PM
> To: Joris Valette
> Cc: Andreas Schwab; Jason Pyeron; git@vger.kernel.org
> Subject: Re: Consider escaping special characters like 'less' does
> 
<snip/>
Show 19 quoted lines
> 
> I.e., something like this would probably help your case 
> without hurting
> anybody:
> 
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index 28b325d754..d44e5ea459 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -714,6 +714,16 @@ sub parse_diff {
>  		push @{$hunk[-1]{DISPLAY}},
>  			(@colored ? $colored[$i] : $diff[$i]);
>  	}
> +
> +	foreach my $hunk (@hunk) {
> +		foreach my $line (@{$hunk->{DISPLAY}}) {
> +			# all control chars minus newline and 
> ESC (for color)
> +			if ($line =~ s/[\000-\011\013-\032\034-\037]/?/g) {
What about CR [0x0D] ?
Show 27 quoted lines
> +				$hunk->{CONTROLCHARS} = 1;
> +			}
> +		}
> +	}
> +
>  	return @hunk;
>  }
>  
> @@ -1407,6 +1417,9 @@ sub patch_update_file {
>  		if ($hunk[$ix]{TYPE} eq 'hunk') {
>  			$other .= ',e';
>  		}
> +		if ($hunk[$ix]->{CONTROLCHARS}) {
> +			print "warning: control characters in 
> hunk have been replaced by '?'\n";
> +		}
>  		for (@{$hunk[$ix]{DISPLAY}}) {
>  			print;
>  		}
> 
> I can't help but feel this is the tip of a larger iceberg, 
> though. E.g.,
> what about characters outside of the terminal's correct encoding? Or
> broken UTF-8 characters?
> 
> -Peff
> 
Previous: Jeff KingNext: Jeff King
Message 12 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.