lib/PublicInbox/Git.pm | 11 +++++------ t/git.t | 4 ++++ diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 8d3f87d577565ea2f07123d890cde23a043185a5..4601f2599ac674ae96d6bcb7ce2d7681f3b587f2 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -27,12 +27,11 @@ ); # 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 { diff --git a/t/git.t b/t/git.t index 6538b6ca2644d3875f9fc0f36fe326fc55675f50..50ec4fbfc582d518986ad54f112ebca8f04a9451 100644 --- a/t/git.t +++ b/t/git.t @@ -144,4 +144,8 @@ my $config = eval { local $/; <$fh> }; 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();