From de4f65e69b0c15fa1009eea102f759fb169d513b Mon Sep 17 00:00:00 2001 From: Alex Sanford Date: Thu, 2 Nov 2023 19:10:15 -0300 Subject: [PATCH] Fix case where a theme slug is all non-latin characters --- app/models/theme.rb | 2 +- lib/wpscan/helper.rb | 3 +++ spec/lib/helper_spec.rb | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/theme.rb b/app/models/theme.rb index 37da6c915..c05200ca2 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -92,7 +92,7 @@ def parse_style tags: 'Tags', text_domain: 'Text Domain' }.each do |attribute, tag| - instance_variable_set(:"@#{attribute}", parse_style_tag(style_body, tag)) + instance_variable_set(:"@#{attribute}", parse_style_tag(style_body, tag)&.force_encoding('UTF-8')) end end diff --git a/lib/wpscan/helper.rb b/lib/wpscan/helper.rb index 9eaa9ac54..161578db7 100644 --- a/lib/wpscan/helper.rb +++ b/lib/wpscan/helper.rb @@ -16,5 +16,8 @@ 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 diff --git a/spec/lib/helper_spec.rb b/spec/lib/helper_spec.rb index a19826645..680e53808 100644 --- a/spec/lib/helper_spec.rb +++ b/spec/lib/helper_spec.rb @@ -7,7 +7,8 @@ '12-slug' => :D_12Slug, 'slug.s' => :SlugS, 'slug yolo $' => :SlugYolo, - 'slug $ ab.cd/12' => :SlugAbCd12 + 'slug $ ab.cd/12' => :SlugAbCd12, + 'カスタムテーマ' => :HexSlug_e382abe382b9e382bfe383a0e38386e383bce3839e }.each do |slug, expected_symbol| context "when #{slug}" do it "returns #{expected_symbol}" do