Replace the core of the text generation methods; previously, these could result in an oddball string result that would not auto-convert into ASCII-8BIT. Looks like a strange corner case in Ruby 1.9
git-svn-id: file:///home/svn/framework3/trunk@9254 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
aedf63c063
commit
5f23151c22
|
@ -626,22 +626,11 @@ module Text
|
||||||
|
|
||||||
# Base text generator method
|
# Base text generator method
|
||||||
def self.rand_base(len, bad, *foo)
|
def self.rand_base(len, bad, *foo)
|
||||||
# Remove restricted characters
|
cset = (foo.join.unpack("C*") - bad.to_s.unpack("C*")).uniq
|
||||||
(bad || '').split('').each { |c| foo.delete(c) }
|
return if cset.length == 0
|
||||||
|
outp = []
|
||||||
# Return nil if all bytes are restricted
|
len.times { outp << cset[rand(cset.length)] }
|
||||||
return nil if foo.length == 0
|
outp.pack("C*")
|
||||||
|
|
||||||
buff = ""
|
|
||||||
|
|
||||||
# Generate a buffer from the remaining bytes
|
|
||||||
if foo.length >= 256
|
|
||||||
len.times { buff << Kernel.rand(256) }
|
|
||||||
else
|
|
||||||
len.times { buff << foo[ rand(foo.length) ] }
|
|
||||||
end
|
|
||||||
|
|
||||||
return buff
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate random bytes of data
|
# Generate random bytes of data
|
||||||
|
|
Loading…
Reference in New Issue