Skip to content

Commit e34c751

Browse files
author
Brent Cook
committed
only use regex matches if they are specified
1 parent e9be0d3 commit e34c751

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/rex/ui/text/table.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def initialize(opts = {})
7272
self.prefix = opts['Prefix'] || ''
7373
self.postfix = opts['Postfix'] || ''
7474
self.colprops = []
75-
self.scterm = opts['SearchTerm'] ? /#{opts['SearchTerm']}/mi : /./
75+
self.scterm = /#{opts['SearchTerm']}/mi if opts['SearchTerm']
7676

7777
self.sort_index = opts['SortIndex'] || 0
7878
self.sort_order = opts['SortOrder'] || :forward
@@ -114,7 +114,7 @@ def to_s
114114
if (is_hr(row))
115115
str << hr_to_s
116116
else
117-
str << row_to_s(row) if row_to_s(row).match(self.scterm)
117+
str << row_to_s(row) if row_visible(row)
118118
end
119119
}
120120

@@ -130,10 +130,9 @@ def to_csv
130130
str = ''
131131
str << ( columns.join(",") + "\n" )
132132
rows.each { |row|
133-
next if is_hr(row) or !(row_to_s(row).match(self.scterm))
133+
next if is_hr(row) || !row_visible(row)
134134
str << ( row.map{|x|
135135
x = x.to_s
136-
137136
x.gsub(/[\r\n]/, ' ').gsub(/\s+/, ' ').gsub('"', '""')
138137
}.map{|x| "\"#{x}\"" }.join(",") + "\n" )
139138
}
@@ -298,6 +297,14 @@ def [](*col_names)
298297

299298
protected
300299

300+
#
301+
# Returns if a row should be visible or not
302+
#
303+
def row_visible(row)
304+
return true if self.scterm.nil?
305+
row_to_s(row).match(self.scterm)
306+
end
307+
301308
#
302309
# Defaults cell widths and alignments.
303310
#
@@ -328,9 +335,7 @@ def columns_to_s # :nodoc:
328335
padding = pad(' ', last_col, last_idx)
329336
nameline << padding
330337
remainder = padding.length - cellpad
331-
if (remainder < 0)
332-
remainder = 0
333-
end
338+
remainder = 0 if remainder < 0
334339
barline << (' ' * (cellpad + remainder))
335340
end
336341

@@ -391,7 +396,7 @@ def pad(chr, buf, colidx, use_cell_pad = true) # :nodoc:
391396
if (use_cell_pad)
392397
val << ' ' * cellpad
393398
end
394-
399+
395400
return val
396401
end
397402

0 commit comments

Comments
 (0)