Method: Asciidoctor::AbstractNode#normalize_system_path

Defined in:
lib/asciidoctor/abstract_node.rb

#normalize_system_path(target, start = nil, jail = nil, opts = {}) ⇒ String

Resolve and normalize a secure path from the target and start paths using the PathResolver.

See PathResolver#system_path for details.

The most important functionality in this method is to prevent resolving a path outside of the jail (which defaults to the directory of the source file, stored in the base_dir instance variable on Document) if the document safe level is set to SafeMode::SAFE or greater (a condition which is true by default).

Parameters:

  • target

    the String target path

  • start (defaults to: nil)

    the String start (i.e., parent) path

  • jail (defaults to: nil)

    the String jail path to confine the resolved path

  • opts (defaults to: {})

    an optional Hash of options to control processing (default: {}): * :recover is used to control whether the processor should automatically recover when an illegal path is encountered * :target_name is used in messages to refer to the path being resolved

  • raises

    a SecurityError if a jail is specified and the resolved path is

  • outside

    the jail.

Returns:

  • (String)

    Returns the String path resolved from the start and target paths, with any parent references resolved and self references removed. If a jail is provided, this path will be guaranteed to be contained within the jail.



458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'lib/asciidoctor/abstract_node.rb', line 458

def normalize_system_path target, start = nil, jail = nil, opts = {}
  if (doc = @document).safe < SafeMode::SAFE
    if start
      start = ::File.join doc.base_dir, start unless doc.path_resolver.root? start
    else
      start = doc.base_dir
    end
  else
    start ||= doc.base_dir
    jail ||= doc.base_dir
  end
  doc.path_resolver.system_path target, start, jail, opts
end