View Issue Details

IDProjectCategoryView StatusLast Update
0000091fileGeneralpublic2019-07-21 09:40
Reporteravellable Assigned Tochristos  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version5.33 
Fixed in Version5.38 
Summary0000091: Ruby files are detected properly when require contains '.'
DescriptionMagic test fails to detect ruby file if there's a '.' in "require" statement. That is a valid statement.
Steps To ReproduceSample File

1. Create a file application.rb
# application.rb
require './something.rb'

2. Run file on it
$ file application.rb
application.rb: ASCII text

Expected Result:
application.rb: Ruby script text, ASCII text

Actual Result:
application.rb: ASCII text

Additional InformationSolution:

The regex needs to include periods('.') too,

See attached fixed file for reference. When used,

$ file -m new_ruby application.rb
application.rb: Ruby script text, ASCII text

$ diff new_ruby /usr/share/file/magic/ruby
25c25
< 0 regex \^[[:space:]]*require[[:space:]]'[A-Za-z_/\.]+'
---
> 0 regex \^[[:space:]]*require[[:space:]]'[A-Za-z_/]+'
48c48
< 0 regex \^[[:space:]]*require[[:space:]]'[A-Za-z_/\.]+' Ruby script text
---
> 0 regex \^[[:space:]]*require[[:space:]]'[A-Za-z_/]+' Ruby script text
TagsNo tags attached.

Activities

avellable

2019-07-09 02:20

reporter  

new_ruby (1,812 bytes)   
#------------------------------------------------------------------------------
# $File: ruby,v 1.7 2017/08/14 13:39:18 christos Exp $
# ruby:  file(1) magic for Ruby scripting language
# URL:  http://www.ruby-lang.org/
# From: Reuben Thomas <rrt@sc3d.org>

# Ruby scripts
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
!:strength + 15
!:mime text/x-ruby
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		\^[[: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		\^[[:space:]]*(class|module)[[:space:]][A-Z]
>0	regex		(modul|includ)e\ [A-Z]|def\ [a-z]
>>&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 definition 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
new_ruby (1,812 bytes)   

avellable

2019-07-09 02:21

reporter   ~0003259

I would be more than happy to create a patch. Is there a document about how to contribute?

christos

2019-07-21 09:40

manager   ~0003263

Fixed, thanks!

Issue History

Date Modified Username Field Change
2019-07-09 02:20 avellable New Issue
2019-07-09 02:20 avellable File Added: new_ruby
2019-07-09 02:21 avellable Note Added: 0003259
2019-07-21 09:40 christos Assigned To => christos
2019-07-21 09:40 christos Status new => assigned
2019-07-21 09:40 christos Status assigned => resolved
2019-07-21 09:40 christos Resolution open => fixed
2019-07-21 09:40 christos Fixed in Version => 5.38
2019-07-21 09:40 christos Note Added: 0003263