File tree 2 files changed +13
-13
lines changed
2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -46,16 +46,11 @@ def malware?
46
46
unl0ck3r h4ck m0ney 0day exploit expl0it ) . any? { |i | !!( self =~ /#{ i } /i ) }
47
47
end
48
48
49
- def near_match? other , percent = 80
50
- min_length = [ self . length , other . length ] . min
51
-
52
- match_count = 0
53
-
54
- min_length . times do |i |
55
- match_count += 1 if self [ i ] == other [ i ]
56
- end
57
-
58
- ( match_count . to_f / min_length ) * 100 >= percent
49
+ def near_match? other , threshold = 0.8
50
+ intersection = ( self . chars & other . chars ) . uniq . length
51
+ union = ( self . chars | other . chars ) . uniq . length
52
+ similarity = intersection . to_f / union
53
+ similarity > threshold
59
54
end
60
55
61
56
def translate_url
Original file line number Diff line number Diff line change 88
88
end
89
89
90
90
it "is true when name and description are near matches" do
91
- repo . name = "MyProject91262"
92
- repo . description = "MyPorject91262"
93
- expect ( repo ) . to be_malware
91
+ [
92
+ [ "MyProject91262" , "MyPorject91262" ] ,
93
+ [ "-Projectus2" , "Projectus2" ]
94
+ ] . each do |tuple |
95
+ repo . name = tuple [ 0 ]
96
+ repo . description = tuple [ 1 ]
97
+ expect ( repo ) . to be_malware
98
+ end
94
99
end
95
100
96
101
it "is false when name and description are not near matches" do
You can’t perform that action at this time.
0 commit comments