Sha256: f3c1af0742599140171d50df3ef6515be99bed9439bae5f9320d4bb01ee78584

Contents?: true

Size: 763 Bytes

Versions: 3

Compression:

Stored size: 763 Bytes

Contents

# frozen_string_literal: true

def read_json_file(file)
  JSON.parse(File.read(file))
rescue StandardError => e
  raise "JSON parsing error in #{file} #{e}"
end

# Sanitize and classify a slug
# @note As a class can not start with a digit or underscore, a D_ is
#       put as a prefix in such case. Ugly but well :x
#       Not only used to classify slugs though, but Dynamic Finder names as well
#
# @return [ Symbol ]
def classify_slug(slug)
  classified = slug.to_s.gsub(/[^a-z\d\-]/i, '-').gsub(/-{1,}/, '_').camelize.to_s
  classified = "D_#{classified}" if /\d/.match?(classified[0])

  # Special case for slugs with all non-latin characters.
  classified = "HexSlug_#{slug.bytes.map { |i| i.to_s(16) }.join}" if classified.empty?

  classified.to_sym
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wpscan-3.8.28 lib/wpscan/helper.rb
wpscan-3.8.27 lib/wpscan/helper.rb
wpscan-3.8.26 lib/wpscan/helper.rb