Resolves: #1050897 - Ruby script recognition and classification

This commit is contained in:
Marek Cermak 2017-08-18 08:53:12 +02:00
parent 1e8f3a1a8d
commit 780ed38dc8
2 changed files with 83 additions and 1 deletions

View File

@ -0,0 +1,78 @@
From d56eb7ea0b9c2a4edec17032a92fe66aebb1aa3a Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Mon, 14 Aug 2017 13:39:18 +0000
Subject: [PATCH] improvements (Marek Cermak)
Fixed Ruby script recognition and classification
https://bugzilla.redhat.com/show_bug.cgi?id=1050897
Upstream commit: https://github.com/file/file/commit/d56eb7ea0b9c2a4edec17032a92fe66aebb1aa3a
Signed-off-by: Marek Cermak <macermak@redhat.com>
---
magic/Magdir/ruby | 35 +++++++++++++++++++++++++++--------
1 file changed, 27 insertions(+), 8 deletions(-)
diff --git a/magic/Magdir/ruby b/magic/Magdir/ruby
index cc3abd0..a6b73d9 100644
--- a/magic/Magdir/ruby
+++ b/magic/Magdir/ruby
@@ -6,27 +6,46 @@
# From: Reuben Thomas <rrt@sc3d.org>
# Ruby scripts
-0 search/1/w #!\ /usr/bin/ruby Ruby script text executable
+0 search/1/w #!\ /usr/bin/ruby Ruby script text executable
!:strength + 15
!:mime text/x-ruby
0 search/1/w #!\ /usr/local/bin/ruby Ruby script text executable
!:strength + 15
!:mime text/x-ruby
-0 search/1 #!/usr/bin/env\ ruby Ruby script text executable
+0 search/1 #!/usr/bin/env\ ruby Ruby script text executable
!:strength + 15
!:mime text/x-ruby
-0 search/1 #!\ /usr/bin/env\ ruby Ruby script text executable
+0 search/1 #!\ /usr/bin/env\ ruby Ruby script text executable
!:strength + 15
!:mime text/x-ruby
# What looks like ruby, but does not have a shebang
# (modules and such)
# From: Lubomir Rintel <lkundrak@v3.sk>
-0 regex \^[\ \t]*require[\ \t]'[A-Za-z_/]+'
->0 regex include\ [A-Z]|def\ [a-z]|\ do$
->>0 regex \^[\ \t]*end([\ \t]*[;#].*)?$ Ruby script text
+0 regex \^[[:space:]]*require[[:space:]]'[A-Za-z_/]+'
+>0 regex def\ [a-z]|\ do$
+>>&0 regex \^[[:space:]]*end([[:space:]]+[;#].*)?$ Ruby script text
+!:strength + 30
!:mime text/x-ruby
-0 regex \^[\ \t]*(class|module)[\ \t][A-Z]
+0 regex \^[[:space:]]*(class|module)[[:space:]][A-Z]
>0 regex (modul|includ)e\ [A-Z]|def\ [a-z]
->>0 regex \^[\ \t]*end([\ \t]*[;#].*)?$ Ruby module source text
+>>&0 regex \^[[:space:]]*end([[:space:]]+[;#].*)?$ Ruby script text
+!:strength + 30
+!:mime text/x-ruby
+# Classes with no modules or defs, beats simple ASCII
+0 regex \^[[:space:]]*(class|module)[[:space:]][A-Z]
+>&0 regex \^[[:space:]]*end([[:space:]]+[;#if].*)?$ Ruby script text
+!:strength + 10
+!:mime text/x-ruby
+# Looks for function definiton to balance python magic
+# def name (args)
+# end
+0 regex \^[[:space:]]*def\ [a-z]|def\ [[:alpha:]]+::[a-z]
+>&0 regex \^[[:space:]]*end([[:space:]]+[;#].*)?$ Ruby script text
+!:strength + 10
+!:mime text/x-ruby
+
+0 regex \^[[:space:]]*require[[:space:]]'[A-Za-z_/]+' Ruby script text
+!:mime text/x-ruby
+0 regex \^[[:space:]]*include\ ([A-Z]+[a-z]*(::))+ Ruby script text
!:mime text/x-ruby
--
2.13.3

View File

@ -3,7 +3,7 @@
Summary: A utility for determining file types
Name: file
Version: 5.31
Release: 8%{?dist}
Release: 9%{?dist}
License: BSD
Group: Applications/File
Source0: ftp://ftp.astron.com/pub/file/file-%{version}.tar.gz
@ -20,6 +20,7 @@ Patch5: file-5.04-man-return-code.patch
Patch6: file-5.31-mo-file-recognition.patch
Patch7: file-5.31-awk-perl-recognition.patch
Patch8: file-5.31-gconv-cache-recognition.patch
Patch9: file-5.31-ruby-recognition.patch
URL: http://www.darwinsys.com/file/
Requires: file-libs = %{version}-%{release}
@ -184,6 +185,9 @@ cd %{py3dir}
%endif
%changelog
* Fri Aug 18 2017 Marek Cermak <macermak@redhat.com> - 5.31-9
- Ruby script recognition and classification (#1050897)
* Mon Aug 14 2017 Marek Cermak <macermak@redhat.com> - 5.31-8
- New magic entry for iconv/gconv module configuration cache (#1342428)