Skip to content

Commit 508217c

Browse files
committed
sanitizepath
1 parent ddc113d commit 508217c

File tree

3 files changed

+9
-51
lines changed

3 files changed

+9
-51
lines changed

package-lock.json

Lines changed: 1 addition & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
"@contentstack/cli-command": "^1.3.2",
99
"@contentstack/cli-utilities": "^1.8.0",
1010
"@contentstack/types-generator": "^2.0.3",
11-
"async": "^3.2.6",
1211
"dotenv": "^16.4.7",
1312
"fancy-test": "^3.0.16",
14-
"graphql": "^16.8.1",
15-
"lodash": "^4.17.21",
16-
"prettier": "^3.4.2",
17-
"tslib": "^2.8.1"
13+
"prettier": "^3.4.2"
1814
},
1915
"devDependencies": {
2016
"@oclif/plugin-help": "^3.3.1",
@@ -63,7 +59,7 @@
6359
"repository": "Contentstack-Solutions/contentstack-cli-tsgen",
6460
"scripts": {
6561
"postpack": "rm -f oclif.manifest.json",
66-
"posttest": "eslint . --ext .ts --config .eslintrc",
62+
"posttest": "eslint . --ext .ts --config .eslintrc --fix",
6763
"prepack": "rm -rf lib && tsc -b && oclif manifest && oclif readme",
6864
"test": "jest --testPathPattern=tests",
6965
"version": "oclif readme && git add README.md",

src/lib/helper.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
export const sanitizePath = (str: string) => str?.replace(/^(\.\.(\/|\\|$))+/, '');
1+
export const sanitizePath = (str: string) => {
2+
return str
3+
?.replace(/^([\/\\])+/, "./") // Normalize leading slashes/backslashes to ''
4+
.replace(/[\/\\]+/g, "/") // Replace multiple slashes/backslashes with a single '/'
5+
.replace(/(\.\.(\/|\\|$))+/g, ""); // Remove directory traversal (../ or ..\)
6+
}

0 commit comments

Comments
 (0)