You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-4Lines changed: 24 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,8 @@ A type-safe abstraction for platform-independent file system paths.
8
8
fullPath = rootDir </> dir "baz" </> file "foo.png"
9
9
```
10
10
11
+
See the [examples file](/examples/Examples.purs) for more.
12
+
11
13
# Getting Started
12
14
13
15
## Installation
@@ -41,11 +43,12 @@ Many paths come from user-input or configuration data. Pathy can parse such stri
41
43
Building path liberals is easy. You will typically build path literals from the following components:
42
44
43
45
*`rootDir`— The root directory of an absolute path.
44
-
*`currentDir`— The current directory (AKA the "working directory"), useful for describing relative paths.
46
+
*`currentDir`— The current directory (AKA the "working directory"), useful for building relative paths.
45
47
*`file`— A file (in the current directory).
46
48
*`dir`— A directory (in the current directory).
47
-
*`(</>)`—Combines two paths into one, if the composition makes sense!
49
+
*`(</>)`—Adds a relative path to the end of a (relative or absolute) path.
48
50
*`(<.>)`— Sets the extension of a file path.
51
+
*`(<..>)`— Ascends one level in a directory, then descends into the specified relative path.
49
52
50
53
For example:
51
54
@@ -85,9 +88,26 @@ Pathy also carries information on whether a path is a file or directory, and whe
85
88
86
89
`parentDir'`
87
90
88
-
`sandbox`
91
+
### Sandboxing
92
+
93
+
Pathy makes it easy to create relative paths, even paths that ascend into parent directories of relative paths.
94
+
95
+
With this power comes danger: if you parse a user string, the user may be able to escape any arbitrary directory.
96
+
97
+
Pathy solves this security problem by *disallowing* conversion from a `Path` to a `String` until the `Path` has been *sandboxed*.
98
+
99
+
To sandbox a path, you just call `sandbox` and provide the sandbox directory, as well as the path to sandbox:
100
+
101
+
```purescript
102
+
sandbox (rootDir </> dir "foo") (rootDir </> dir "foo" </> dir "bar")
103
+
```
104
+
105
+
This returns a `Maybe`, which is either equal to `Nothing` if the tainted path escapes the sandbox, or `Just p`, where `p` is the tainted path, relative to the sandbox path.
106
+
107
+
After you have sandboxed a foreign path, you may call `printPath` on it. There's no need to remember this rule because it's enforced at compile-time by phantom types!
89
108
109
+
All the path literals you build by hand are automatically sandboxed, unless you call `parentDir'` on them.
90
110
91
111
# API Docs
92
112
93
-
[MODULES.md](MODULES.md)
113
+
For complete documentation on all functions and types, see [MODULES.md](MODULES.md).
0 commit comments