diff options
-rw-r--r-- | lib/PublicInbox/Git.pm | 11 | ||||
-rw-r--r-- | t/git.t | 4 |
2 files changed, 9 insertions, 6 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 8d3f87d5..4601f259 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -27,12 +27,11 @@ my %GIT_ESC = ( # unquote pathnames used by git, see quote.c::unquote_c_style.c in git.git sub git_unquote ($) { - my ($s) = @_; - return $s unless ($s =~ /\A"(.*)"\z/); - $s = $1; - $s =~ s/\\([abfnrtv])/$GIT_ESC{$1}/g; - $s =~ s/\\([0-7]{1,3})/chr(oct($1))/ge; - $s; + return $_[0] unless ($_[0] =~ /\A"(.*)"\z/); + $_[0] = $1; + $_[0] =~ s/\\([abfnrtv])/$GIT_ESC{$1}/g; + $_[0] =~ s/\\([0-7]{1,3})/chr(oct($1))/ge; + $_[0]; } sub new { @@ -144,4 +144,8 @@ if ('alternates reloaded') { is($$found, $config, 'alternates reloaded'); } +use_ok 'PublicInbox::Git', qw(git_unquote); +is("foo\nbar", git_unquote('"foo\\nbar"'.''), 'unquoted newline'); +is("Eléanor", git_unquote('"El\\303\\251anor"'.''), 'unquoted octal'); + done_testing(); |