path-sanitizer 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,20 +13,23 @@ jobs:
13
13
  runs-on: ubuntu-latest
14
14
 
15
15
  steps:
16
- - name: Checkout code
17
- uses: actions/checkout@v3
16
+ - name: Checkout
17
+ uses: actions/checkout@v4
18
18
 
19
- - name: Setup Node.js
20
- uses: actions/setup-node@v3
19
+ - uses: pnpm/action-setup@v4
20
+ name: Install pnpm
21
21
  with:
22
- node-version: 18
23
- cache: 'pnpm'
22
+ version: 9
23
+ run_install: false
24
24
 
25
- - name: Install pnpm
26
- run: npm install -g pnpm
25
+ - name: Install Node.js
26
+ uses: actions/setup-node@v4
27
+ with:
28
+ node-version: 22
29
+ cache: 'pnpm'
27
30
 
28
31
  - name: Install dependencies
29
32
  run: pnpm install
30
33
 
31
34
  - name: Run tests
32
- run: pnpm test
35
+ run: pnpm test
package/dist/index.d.ts CHANGED
@@ -27,5 +27,8 @@ interface SanitizeOptionsComplete {
27
27
  notAllowedRegEx: RegExp;
28
28
  }
29
29
  export declare const DEFAULT_OPTIONS: SanitizeOptionsComplete;
30
+ /**
31
+ * Sanitizes a portion of a path to avoid Path Traversal
32
+ */
30
33
  export default function sanitize(pathstr: string, options?: SanitizeOptions): string;
31
34
  export {};
package/dist/index.js CHANGED
@@ -21,6 +21,9 @@ exports.DEFAULT_OPTIONS = {
21
21
  parentDirectoryRegEx: /[\/\\]\.\.[\/\\]/g,
22
22
  notAllowedRegEx: /:|\$|!|'|"|@|\+|`|\||=/g
23
23
  };
24
+ /**
25
+ * Sanitizes a portion of a path to avoid Path Traversal
26
+ */
24
27
  function sanitize(pathstr, options = exports.DEFAULT_OPTIONS) {
25
28
  if (!options)
26
29
  options = exports.DEFAULT_OPTIONS;
@@ -71,5 +74,7 @@ function sanitize(pathstr, options = exports.DEFAULT_OPTIONS) {
71
74
  sanitizedPath = sanitizedPath.replace(/[\\]/g, '/');
72
75
  // Replace double (back)slashes with a single slash
73
76
  sanitizedPath = sanitizedPath.replace(/[\/\\]+/g, '/');
74
- return sanitizedPath;
77
+ // Make sure out is not "."
78
+ sanitizedPath = sanitizedPath.trim() === '.' ? '' : sanitizedPath;
79
+ return sanitizedPath.trim();
75
80
  }
package/package.json CHANGED
@@ -1,26 +1,27 @@
1
- {
2
- "name": "path-sanitizer",
3
- "version": "3.0.0",
4
- "description": "A simple lightweight npm package for sanitizing paths to prevent Path Traversal",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "test": "vitest"
8
- },
9
- "keywords": [],
10
- "author": "Cabra (https://github.com/cabraviva)",
11
- "license": "MIT",
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/cabraviva/path-sanitizer.git"
15
- },
16
- "bugs": {
17
- "url": "https://github.com/cabraviva/path-sanitizer/issues"
18
- },
19
- "homepage": "https://github.com/cabraviva/path-sanitizer#readme",
20
- "types": "dist/index.d.ts",
21
- "devDependencies": {
22
- "@types/node": "^22.9.3",
23
- "typescript": "^5.7.2",
24
- "vitest": "^2.1.5"
25
- }
1
+ {
2
+ "name": "path-sanitizer",
3
+ "version": "3.0.1",
4
+ "description": "A simple lightweight npm package for sanitizing paths to prevent Path Traversal",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "vitest",
8
+ "build": "tsc"
9
+ },
10
+ "keywords": [],
11
+ "author": "Cabra (https://github.com/cabraviva)",
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/cabraviva/path-sanitizer.git"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/cabraviva/path-sanitizer/issues"
19
+ },
20
+ "homepage": "https://github.com/cabraviva/path-sanitizer#readme",
21
+ "types": "dist/index.d.ts",
22
+ "devDependencies": {
23
+ "@types/node": "^22.9.3",
24
+ "typescript": "^5.7.2",
25
+ "vitest": "^2.1.5"
26
+ }
26
27
  }
package/tsconfig.json CHANGED
@@ -1,15 +1,15 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNEXT",
4
- "module": "commonjs",
5
- "declaration": true,
6
- "outDir": "./dist",
7
- "strict": true
8
- },
9
- "include": [
10
- "lib/*.ts"
11
- ],
12
- "exclude": [
13
- "lib/*.test.ts"
14
- ]
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNEXT",
4
+ "module": "commonjs",
5
+ "declaration": true,
6
+ "outDir": "./dist",
7
+ "strict": true
8
+ },
9
+ "include": [
10
+ "lib/*.ts"
11
+ ],
12
+ "exclude": [
13
+ "lib/*.test.ts"
14
+ ]
15
15
  }