Puppet Function: simplib::safe_filename

Defined in:
functions/safe_filename.pp
Function type:
Puppet Language

Overview

simplib::safe_filename(String $input, String[1] $pattern = '[\\\\/?*:|"<>]', String[1] $replacement = '__')String

Convert a string into a filename that is ‘path safe’

The goal is to ensure that files do not contain characters that may accidentally turn into deeper path entries or invalid filenames.

This is not perfect but should be sufficient for most cases and can be improved over time.

Parameters:

  • input (String)

    String that should be converted into a ‘path safe’ filename

  • pattern (String[1]) (defaults to: '[\\\\/?*:|"<>]')

    The pattern to be used to match characters that may cause issues in filenames

  • replacement (String[1]) (defaults to: '__')

    String that should be used to replace all instances of unsafe characters in ‘$input`

Returns:

  • (String)


20
21
22
23
24
25
26
# File 'functions/safe_filename.pp', line 20

function simplib::safe_filename (
  String    $input,
  String[1] $pattern = '[\\\\/?*:|"<>]',
  String[1] $replacement = '__'
) {
  regsubst($input, $pattern, $replacement, 'G')
}