Skip to content

Commit

Permalink
Fix case where a theme slug is all non-latin characters
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsanford committed Nov 2, 2023
1 parent bce3b48 commit de4f65e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/theme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions lib/wpscan/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion spec/lib/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de4f65e

Please sign in to comment.