Fixed bug where C<-T>/C<-B> were being called on strings.
Dan Brook [Wed, 14 Apr 2010 13:53:03 +0000 (14:53 +0100)]
lib/Gitalist/Controller/Fragment/Ref.pm
lib/Gitalist/Controller/Ref.pm
lib/Gitalist/Git/Repository.pm
lib/Gitalist/Utils.pm

index 2917616..65e4a61 100644 (file)
@@ -86,7 +86,7 @@ after blob => sub {
         # XXX Hack hack hack, see View::SyntaxHighlight
         language  => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
         is_image  => File::Type::WebImages::mime_type($c->stash->{blob}),
-        is_binary => -B $c->stash->{blob},
+        is_binary => Gitalist::Utils::is_binary($c->stash->{blob}),
     );
 
     $c->forward('View::SyntaxHighlight')
index b988d4d..207d4ca 100644 (file)
@@ -23,7 +23,7 @@ sub raw : Chained('find') Does('FilenameArgs') Args() {
     my ($self, $c) = @_;
     $c->forward('find_blob');
 
-    if(-T $c->stash->{blob}) {
+    if(!Gitalist::Utils::is_binary($c->stash->{blob})) {
         $c->response->content_type('text/plain; charset=utf-8');
     } else {
         my $ft = File::Type->new();
index 7e873cd..0d0c884 100644 (file)
@@ -135,7 +135,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
             if !$sha1 || $sha1 !~ $SHA1RE;
 
         my @search_opts;
-        if ($search) {
+        if ($search and exists $search->{text}) {
             $search->{type} = 'grep'
                 if $search->{type} eq 'commit';
             @search_opts = (
index 0df4973..c40d825 100644 (file)
@@ -45,6 +45,12 @@ sub age_string {
   return $age_str;
 }
 
+sub is_binary {
+  my($str) = @_;
+  open my $fh, '<', \$str or return;
+  return -B $fh;
+}
+
 1;
 
 __END__
@@ -57,7 +63,11 @@ Gitalist::Utils - trivial utils for Gitalist
 
 =head2 age_string
 
-Turns an integer number of seconds into a string..
+Turns an integer number of seconds into a string.
+
+=head2 is_binary
+
+Check whether a string is binary according to C<-B>.
 
 =head1 AUTHORS