From bee5ca66720c97db4334a6df3a58e625e334be50 Mon Sep 17 00:00:00 2001 From: Marek Cermak Date: Aug 18 2017 08:31:43 +0000 Subject: Resolves: #1050897 - Ruby script recognition and classification --- diff --git a/file-5.31-ruby-recognition.patch b/file-5.31-ruby-recognition.patch new file mode 100644 index 0000000..9794a55 --- /dev/null +++ b/file-5.31-ruby-recognition.patch @@ -0,0 +1,78 @@ +From d56eb7ea0b9c2a4edec17032a92fe66aebb1aa3a Mon Sep 17 00:00:00 2001 +From: Christos Zoulas +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 +--- + 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 + + # 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 +-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 + diff --git a/file.spec b/file.spec index 5f0d133..0335fd0 100644 --- a/file.spec +++ b/file.spec @@ -5,7 +5,7 @@ Summary: A utility for determining file types Name: file Version: 5.29 -Release: 8%{?dist} +Release: 9%{?dist} License: BSD Group: Applications/File Source0: ftp://ftp.astron.com/pub/file/file-%{version}.tar.gz @@ -30,6 +30,7 @@ Patch102: file-5.29-short-sector.patch Patch103: file-5.30-python-utf8.patch Patch104: file-5.31-mo-file-recognition.patch Patch105: file-5.31-gconv-cache-recognition.patch +Patch106: file-5.31-ruby-recognition.patch URL: http://www.darwinsys.com/file/ Requires: file-libs = %{version}-%{release} @@ -107,6 +108,7 @@ file(1) command. %patch103 -p1 %patch104 -p1 %patch105 -p1 +%patch106 -p1 # Patches can generate *.orig files, which can't stay in the magic dir, # otherwise there will be problems with compiling magic file! @@ -214,6 +216,9 @@ cd %{py3dir} %endif %changelog +* Fri Aug 18 2017 Marek Cermak - 5.29-9 +- Ruby script recognition and classification (#1050897) + * Mon Aug 14 2017 Marek Cermak - 5.29-8 - New magic entry for iconv/gconv module configuration cache (#1342428)