Escape lengthy regex, use File instead of IO
This commit is contained in:
Родитель
c37b929021
Коммит
e83b426674
|
@ -307,6 +307,9 @@ module OctocatalogDiff
|
|||
# @param string_in [String] Input string, which might contain trailing whitespace
|
||||
# @return [String] Modified string
|
||||
def self.make_trailing_whitespace_visible(string_in)
|
||||
if string_in.length > 1000
|
||||
raise ArgumentError, "Input string too long"
|
||||
end
|
||||
return string_in unless string_in =~ /\A((?:.|\n)*?)(\s+)(\e\[0m)?\Z/
|
||||
beginning = Regexp.last_match(1)
|
||||
trailing_space = Regexp.last_match(2)
|
||||
|
|
|
@ -155,6 +155,9 @@ module OctocatalogDiff
|
|||
elsif options[:fact_file]
|
||||
raise Errno::ENOENT, "Fact file #{options[:fact_file]} does not exist" unless File.file?(options[:fact_file])
|
||||
fact_file_opts = { fact_file_string: File.read(options[:fact_file]) }
|
||||
if options[:fact_file].length > 1000
|
||||
raise ArgumentError, "Input too long"
|
||||
end
|
||||
fact_file_opts[:backend] = Regexp.last_match(1).to_sym if options[:fact_file] =~ /.*\.(\w+)$/
|
||||
OctocatalogDiff::Facts.new(fact_file_opts)
|
||||
else
|
||||
|
|
|
@ -21,7 +21,7 @@ module OctocatalogDiff
|
|||
@fc ||= {}
|
||||
@fc[filename] ||= begin
|
||||
comments = []
|
||||
IO.readlines(filename).each do |line|
|
||||
File.readlines(filename).each do |line|
|
||||
next if line =~ /^#\s*@/
|
||||
next if line.strip == '# frozen_string_literal: true'
|
||||
if line =~ /^#(.+)/
|
||||
|
|
Загрузка…
Ссылка в новой задаче