Project

General

Profile

Bug #17765 ยป segfault_gsub.rb

lenwood (Paul Martensen), 03/31/2021 11:57 AM

 
1
def sanitize_for_prometheus(string_or_symbol)
2
  reg = /[^a-zA-Z_0-9]/
3
  string_or_symbol.to_s.downcase.gsub(reg, '_')
4
end
5

    
6
def rand_string_or_symbol
7
  @o ||= [('a'..'z').to_a, ('A'..'Z').to_a, (0..9).to_a, '-', '.'].flatten
8
  str = @o.sample(50).join
9
  rand > 0.5 ? str.to_sym : str
10
end
11

    
12
loop { sanitize_for_prometheus rand_string_or_symbol }