Skip to content

Commit

Permalink
Merge pull request #1814 from wpscanteam/fix/non-latin-character-slugs
Browse files Browse the repository at this point in the history
Fix case where a theme slug is all non-latin characters
  • Loading branch information
alexsanford committed Nov 7, 2023
2 parents bce3b48 + de4f65e commit 96b6b81
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 96b6b81

Please sign in to comment.