Class: Coradoc::IncludeResolver::Filesystem
- Inherits:
-
Coradoc::IncludeResolver
- Object
- Coradoc::IncludeResolver
- Coradoc::IncludeResolver::Filesystem
- Defined in:
- lib/coradoc/include_resolver/filesystem.rb
Overview
Default include resolver: reads files from the local filesystem, rooted at base_dir. Path-traversal protection is ON by default to match asciidoctor’s :safe mode.
Pass allow_unsafe: true to opt out (matches :unsafe mode).
Instance Attribute Summary collapse
-
#allow_unsafe ⇒ Object
readonly
Returns the value of attribute allow_unsafe.
-
#base_dir ⇒ Object
readonly
Returns the value of attribute base_dir.
-
#max_bytes ⇒ Object
readonly
Returns the value of attribute max_bytes.
Instance Method Summary collapse
- #call(target:, base_dir:, options:, context:) ⇒ Object
-
#initialize(base_dir:, allow_unsafe: false, max_bytes: nil) ⇒ Filesystem
constructor
A new instance of Filesystem.
Methods inherited from Coradoc::IncludeResolver
Constructor Details
#initialize(base_dir:, allow_unsafe: false, max_bytes: nil) ⇒ Filesystem
Returns a new instance of Filesystem.
24 25 26 27 28 |
# File 'lib/coradoc/include_resolver/filesystem.rb', line 24 def initialize(base_dir:, allow_unsafe: false, max_bytes: nil) @base_dir = File.(base_dir) @allow_unsafe = allow_unsafe @max_bytes = max_bytes end |
Instance Attribute Details
#allow_unsafe ⇒ Object (readonly)
Returns the value of attribute allow_unsafe.
13 14 15 |
# File 'lib/coradoc/include_resolver/filesystem.rb', line 13 def allow_unsafe @allow_unsafe end |
#base_dir ⇒ Object (readonly)
Returns the value of attribute base_dir.
13 14 15 |
# File 'lib/coradoc/include_resolver/filesystem.rb', line 13 def base_dir @base_dir end |
#max_bytes ⇒ Object (readonly)
Returns the value of attribute max_bytes.
13 14 15 |
# File 'lib/coradoc/include_resolver/filesystem.rb', line 13 def max_bytes @max_bytes end |
Instance Method Details
#call(target:, base_dir:, options:, context:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/coradoc/include_resolver/filesystem.rb', line 30 def call(target:, base_dir:, options:, context:) full = File.(target, base_dir) enforce_safety!(full, base_dir) unless allow_unsafe raise Coradoc::IncludeNotFoundError, target unless File.file?(full) enforce_size!(full, target) encoding = &.file_encoding || 'utf-8' read_with_encoding(full, encoding) end |