Class: Natsuzora::TemplateLoader::IncludePathResolver
- Inherits:
-
Object
- Object
- Natsuzora::TemplateLoader::IncludePathResolver
- Defined in:
- lib/natsuzora/template_loader.rb
Instance Method Summary collapse
- #ensure_within_root!(path) ⇒ Object
-
#initialize(include_root) ⇒ IncludePathResolver
constructor
A new instance of IncludePathResolver.
- #resolve_template_path(name) ⇒ Object
Constructor Details
#initialize(include_root) ⇒ IncludePathResolver
Returns a new instance of IncludePathResolver.
6 7 8 9 |
# File 'lib/natsuzora/template_loader.rb', line 6 def initialize(include_root) @include_root = File.(include_root) @include_root_realpath = nil end |
Instance Method Details
#ensure_within_root!(path) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/natsuzora/template_loader.rb', line 17 def ensure_within_root!(path) candidate = canonicalize_candidate(path) root = canonical_root return if within_root?(candidate, root) raise IncludeError, "Path traversal detected: #{path}" end |
#resolve_template_path(name) ⇒ Object
11 12 13 14 15 |
# File 'lib/natsuzora/template_loader.rb', line 11 def resolve_template_path(name) segments = name.split('/').reject(&:empty?) segments[-1] = "_#{segments[-1]}" "#{File.join(@include_root, *segments)}.ntzr" end |