Skip to content

Commit 96b6b81

Browse files
authored
Merge pull request wpscanteam#1814 from wpscanteam/fix/non-latin-character-slugs
Fix case where a theme slug is all non-latin characters
2 parents bce3b48 + de4f65e commit 96b6b81

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

app/models/theme.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def parse_style
9292
tags: 'Tags',
9393
text_domain: 'Text Domain'
9494
}.each do |attribute, tag|
95-
instance_variable_set(:"@#{attribute}", parse_style_tag(style_body, tag))
95+
instance_variable_set(:"@#{attribute}", parse_style_tag(style_body, tag)&.force_encoding('UTF-8'))
9696
end
9797
end
9898

lib/wpscan/helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ def classify_slug(slug)
1616
classified = slug.to_s.gsub(/[^a-z\d\-]/i, '-').gsub(/-{1,}/, '_').camelize.to_s
1717
classified = "D_#{classified}" if /\d/.match?(classified[0])
1818

19+
# Special case for slugs with all non-latin characters.
20+
classified = "HexSlug_#{slug.bytes.map { |i| i.to_s(16) }.join}" if classified.empty?
21+
1922
classified.to_sym
2023
end

spec/lib/helper_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
'12-slug' => :D_12Slug,
88
'slug.s' => :SlugS,
99
'slug yolo $' => :SlugYolo,
10-
'slug $ ab.cd/12' => :SlugAbCd12
10+
'slug $ ab.cd/12' => :SlugAbCd12,
11+
'カスタムテーマ' => :HexSlug_e382abe382b9e382bfe383a0e38386e383bce3839e
1112
}.each do |slug, expected_symbol|
1213
context "when #{slug}" do
1314
it "returns #{expected_symbol}" do

0 commit comments

Comments
 (0)