Class: Plum::ThemeAssetPath
- Inherits:
-
Object
- Object
- Plum::ThemeAssetPath
- Defined in:
- app/services/plum/theme_asset_path.rb
Defined Under Namespace
Classes: UnsafePathError
Class Method Summary collapse
Class Method Details
.normalize(path) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/services/plum/theme_asset_path.rb', line 8 def normalize(path) raw_path = path.to_s raise UnsafePathError, "Theme asset path cannot be blank" if raw_path.blank? raise UnsafePathError, "Theme asset path cannot contain null bytes" if raw_path.include?("\0") parts = raw_path.split("/").reject(&:blank?) if Pathname(raw_path).absolute? || parts.any? { |part| part == "." || part == ".." } raise UnsafePathError, "Theme asset path must stay inside the theme assets directory" end raise UnsafePathError, "Theme asset path cannot be blank" if parts.blank? parts.join("/") end |
.url(base_url:, path:) ⇒ Object
22 23 24 25 26 27 28 |
# File 'app/services/plum/theme_asset_path.rb', line 22 def url(base_url:, path:) encoded_path = normalize(path).split("/").map { |part| ERB::Util.url_encode(part) }.join("/") "#{base_url.to_s.chomp("/")}/#{encoded_path}" rescue UnsafePathError "" end |