| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/sanitize.R |
| 3 |
\name{path_sanitize} |
| 4 |
\alias{path_sanitize} |
| 5 |
\title{Sanitize a filename by removing directory paths and invalid characters} |
| 6 |
\usage{ |
| 7 |
path_sanitize(filename, replacement = "") |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{filename}{A character vector to be sanitized.} |
| 11 |
|
| 12 |
\item{replacement}{A character vector used to replace invalid characters.} |
| 13 |
} |
| 14 |
\description{ |
| 15 |
\code{path_sanitize()} removes the following: |
| 16 |
\itemize{ |
| 17 |
\item \href{https://en.wikipedia.org/wiki/C0_and_C1_control_codes}{Control characters} |
| 18 |
\item \href{https://web.archive.org/web/20230126161942/https://kb.acronis.com/content/39790}{Reserved characters} |
| 19 |
\item Unix reserved filenames (\code{.} and \code{..}) |
| 20 |
\item Trailing periods and spaces (invalid on Windows) |
| 21 |
\item Windows reserved filenames (\code{CON}, \code{PRN}, \code{AUX}, \code{NUL}, \code{COM1}, \code{COM2}, |
| 22 |
\code{COM3}, COM4, \code{COM5}, \code{COM6}, \code{COM7}, \code{COM8}, \code{COM9}, \code{LPT1}, \code{LPT2}, |
| 23 |
\code{LPT3}, \code{LPT4}, \code{LPT5}, \code{LPT6}, LPT7, \code{LPT8}, and \code{LPT9}) |
| 24 |
The resulting string is then truncated to \href{https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits}{255 bytes in length} |
| 25 |
} |
| 26 |
} |
| 27 |
\examples{ |
| 28 |
# potentially unsafe string |
| 29 |
str <- "~/.\u0001ssh/authorized_keys" |
| 30 |
path_sanitize(str) |
| 31 |
|
| 32 |
path_sanitize("..") |
| 33 |
} |
| 34 |
\seealso{ |
| 35 |
\url{https://www.npmjs.com/package/sanitize-filename}, upon which this |
| 36 |
function is based. |
| 37 |
} |