Skip to content

Commit

Permalink
Bugfix regex for removing ANSI color escapes was incomplete
Browse files Browse the repository at this point in the history
It covered simple color escapes like "\e[32m" but not "\e[1;32m".  This
makes colors that matches the latter pattern to spill into gitids.txt,
which makes git-list wrongly thought that it was part of the file name.
  • Loading branch information
nazri committed Mar 22, 2016
1 parent e507e90 commit d8967d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion git-id
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ sub show_and_cache {
$tocache =~ s/{(\d+)}[\t ]{1,2}/\n$1\t/g;
$line =~ s/{(\d+)}/$1/g;
print $line;
$tocache =~ s/\e\[\d*m//g;
$tocache =~ s/\e\[(\d*(;\d*)*)m//g;
if ($untracked_in_columns) {
$tocache =~ s/\s*\n/\n/gms; # Trailing spaces from columnar formatting
}
Expand Down
13 changes: 12 additions & 1 deletion t/006_custom_status_color.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# vim:fdm=marker foldmarker={\:,\:}: commentstring=\ #%s
use strict;
use warnings;
use Test::More tests => 1;
use Test::More tests => 2;

use lib 't/lib';
use Scaffold qw/$workdir $srcdir/;
Expand All @@ -26,3 +26,14 @@ $got = `cd $workdir; $srcdir/git-number --color=always`;
$got =~ s/\e\[\d*m//gs;
$expected = qr/1\tnew file: one.txt\n/ms;
like($got, $expected, $testname); #:}

$testname = "git number with untracked in bold red"; #{:
`
cd $workdir &&
echo 'untracked1' > untracked1.txt &&
git config color.status.untracked 'red bold' &&
$srcdir/git-number --color=always
`;
$got = `cd $workdir; $srcdir/git-list 2`;
$expected = "untracked1.txt\n";
eq_or_diff($got, $expected, $testname); #:}

0 comments on commit d8967d7

Please sign in to comment.