Skip to content

Commit c62f407

Browse files
committed
Added a check for vars_get in msftidy
1 parent 5cf5643 commit c62f407

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

tools/msftidy.rb

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def initialize(source_file)
6464
# @return status [Integer] Returns WARNINGS unless we already have an
6565
# error.
6666
def warn(txt, line=0) line_msg = (line>0) ? ":#{line}" : ''
67-
puts "#{@full_filepath}#{line_msg} - [#{'WARNING'.yellow}] #{txt}"
67+
puts "#{@full_filepath}#{line_msg} - [#{'WARNING'.yellow}] #{cleanup_text(txt)}"
6868
@status == ERRORS ? @status = ERRORS : @status = WARNINGS
6969
end
7070

@@ -76,14 +76,14 @@ def warn(txt, line=0) line_msg = (line>0) ? ":#{line}" : ''
7676
# @return status [Integer] Returns ERRORS
7777
def error(txt, line=0)
7878
line_msg = (line>0) ? ":#{line}" : ''
79-
puts "#{@full_filepath}#{line_msg} - [#{'ERROR'.red}] #{txt}"
79+
puts "#{@full_filepath}#{line_msg} - [#{'ERROR'.red}] #{cleanup_text(txt)}"
8080
@status = ERRORS
8181
end
8282

8383
# Currently unused, but some day msftidy will fix errors for you.
8484
def fixed(txt, line=0)
8585
line_msg = (line>0) ? ":#{line}" : ''
86-
puts "#{@full_filepath}#{line_msg} - [#{'FIXED'.green}] #{txt}"
86+
puts "#{@full_filepath}#{line_msg} - [#{'FIXED'.green}] #{cleanup_text(txt)}"
8787
end
8888

8989

@@ -469,7 +469,7 @@ def check_lines
469469

470470
# do not change datastore in code
471471
if ln =~ /(?<!\.)datastore\[["'][^"']+["']\]\s*=(?![=~>])/
472-
error("datastore is modified in code: #{ln.inspect}", idx)
472+
error("datastore is modified in code: #{ln}", idx)
473473
end
474474
}
475475
end
@@ -481,6 +481,15 @@ def check_vuln_codes
481481
end
482482
end
483483

484+
def check_vars_get
485+
test = @source.scan(/send_request_(?:cgi|raw)\s*\(\s*\{\s*['"]uri['"]\s*=>\s*[^=\}]*?\?[^,\}]+/im)
486+
unless test.empty?
487+
test.each { |item|
488+
warn("Please use vars_get in send_request_cgi and send_request_raw: #{item}")
489+
}
490+
end
491+
end
492+
484493
private
485494

486495
def load_file(file)
@@ -490,6 +499,13 @@ def load_file(file)
490499
f.close
491500
return buf
492501
end
502+
503+
def cleanup_text(txt)
504+
# remove line breaks
505+
txt = txt.gsub(/[\r\n]/, ' ')
506+
# replace multiple spaces by one space
507+
txt.gsub(/\s{2,}/, ' ')
508+
end
493509
end
494510

495511
#
@@ -517,6 +533,7 @@ def run_checks(full_filepath)
517533
tidy.check_snake_case_filename
518534
tidy.check_comment_splat
519535
tidy.check_vuln_codes
536+
tidy.check_vars_get
520537
return tidy
521538
end
522539

0 commit comments

Comments
 (0)