Delete file: validation on normalization again
parent
57df5c4f4f
commit
66d23e3b5e
|
@ -14,21 +14,18 @@ class OptAddressRange < OptBase
|
|||
|
||||
def normalize(value)
|
||||
return nil unless value.kind_of?(String)
|
||||
if (value =~ /^file:(.*)/)
|
||||
path = $1
|
||||
return false if not File.exists?(path) or File.directory?(path)
|
||||
return File.readlines(path).map{ |s| s.strip}.join(" ")
|
||||
elsif (value =~ /^rand:(.*)/)
|
||||
if value =~ /^rand:(.*)/
|
||||
count = $1.to_i
|
||||
return false if count < 1
|
||||
ret = ''
|
||||
count.times {
|
||||
ret << " " if not ret.empty?
|
||||
ret << [ rand(0x100000000) ].pack("N").unpack("C*").map{|x| x.to_s }.join(".")
|
||||
}
|
||||
count.times do
|
||||
ret << ' ' if not ret.empty?
|
||||
ret << [ rand(0x100000000) ].pack('N').unpack('C*').map{|x| x.to_s }.join('.')
|
||||
end
|
||||
return ret
|
||||
end
|
||||
return value
|
||||
|
||||
value
|
||||
end
|
||||
|
||||
def valid?(value)
|
||||
|
|
|
@ -13,14 +13,6 @@ class OptRaw < OptBase
|
|||
end
|
||||
|
||||
def normalize(value)
|
||||
if (value =~ /^file:(.*)/)
|
||||
path = $1
|
||||
begin
|
||||
value = File.read(path)
|
||||
rescue ::Errno::ENOENT, ::Errno::EISDIR
|
||||
value = nil
|
||||
end
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
|
|
|
@ -13,14 +13,6 @@ class OptString < OptBase
|
|||
end
|
||||
|
||||
def normalize(value)
|
||||
if (value =~ /^file:(.*)/)
|
||||
path = $1
|
||||
begin
|
||||
value = File.read(path)
|
||||
rescue ::Errno::ENOENT, ::Errno::EISDIR
|
||||
value = nil
|
||||
end
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue