File: path_sanitize.Rd

package info (click to toggle)
r-cran-fs 1.6.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 744 kB
  • sloc: cpp: 1,288; ansic: 530; sh: 13; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sanitize.R
\name{path_sanitize}
\alias{path_sanitize}
\title{Sanitize a filename by removing directory paths and invalid characters}
\usage{
path_sanitize(filename, replacement = "")
}
\arguments{
\item{filename}{A character vector to be sanitized.}

\item{replacement}{A character vector used to replace invalid characters.}
}
\description{
\code{path_sanitize()} removes the following:
\itemize{
\item \href{https://en.wikipedia.org/wiki/C0_and_C1_control_codes}{Control characters}
\item \href{https://kb.acronis.com/content/39790}{Reserved characters}
\item Unix reserved filenames (\code{.} and \code{..})
\item Trailing periods and spaces (invalid on Windows)
\item Windows reserved filenames (\code{CON}, \code{PRN}, \code{AUX}, \code{NUL}, \code{COM1}, \code{COM2},
\code{COM3}, COM4, \code{COM5}, \code{COM6}, \code{COM7}, \code{COM8}, \code{COM9}, \code{LPT1}, \code{LPT2},
\code{LPT3}, \code{LPT4}, \code{LPT5}, \code{LPT6}, LPT7, \code{LPT8}, and \code{LPT9})
The resulting string is then truncated to \href{https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits}{255 bytes in length}
}
}
\examples{
# potentially unsafe string
str <- "~/.\u0001ssh/authorized_keys"
path_sanitize(str)

path_sanitize("..")
}
\seealso{
\url{https://www.npmjs.com/package/sanitize-filename}, upon which this
function is based.
}