Reactively check for invalid module names
parent
29f36a3921
commit
0b8926715e
|
@ -362,17 +362,24 @@ class Msf::Modules::Loader::Base
|
|||
# @return [nil] if any module name along the chain does not exist.
|
||||
def current_module(module_names)
|
||||
# Don't want to trigger ActiveSupport's const_missing, so can't use constantize.
|
||||
named_module = module_names.inject(Object) { |parent, module_name|
|
||||
named_module = module_names.reduce(Object) do |parent, module_name|
|
||||
# Since we're searching parent namespaces first anyway, this is
|
||||
# semantically equivalent to providing false for the 1.9-only
|
||||
# "inherit" parameter to const_defined?. If we ever drop 1.8
|
||||
# support, we can save a few cycles here by adding it back.
|
||||
if parent.const_defined?(module_name)
|
||||
parent.const_get(module_name)
|
||||
else
|
||||
break
|
||||
begin
|
||||
if parent.const_defined?(module_name)
|
||||
parent.const_get(module_name)
|
||||
else
|
||||
break
|
||||
end
|
||||
# HACK: This doesn't slow load time as much as checking proactively
|
||||
rescue NameError
|
||||
reversed_name = self.class.reverse_relative_name(module_name)
|
||||
# TODO: Consolidate this with Msftidy#check_snake_case_filename ?
|
||||
raise Msf::ModuleLoadError, "#{reversed_name} must be lowercase alphanumeric snake case"
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
named_module
|
||||
end
|
||||
|
|
|
@ -257,7 +257,7 @@ class Msftidy
|
|||
# This check also enforces namespace module name reversibility
|
||||
def check_snake_case_filename
|
||||
if @name !~ /^[a-z0-9]+(?:_[a-z0-9]+)*\.rb$/
|
||||
warn('Filenames should be lowercase alphanumeric snake case.')
|
||||
warn('Filenames must be lowercase alphanumeric snake case.')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue