Skip to content
6 changes: 5 additions & 1 deletion src/lib/helper.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const sanitizePath = (str: string) => str?.replace(/^(\.\.(\/|\\|$))+/, '');
export const sanitizePath = (str: string) =>
str
?.replace(/^([\/\\])+/, "./") // Normalize leading slashes/backslashes to './'
.replace(/[\/\\]+/g, "/") // Replace multiple slashes/backslashes with a single '/'
.replace(/(\.\.(\/|\\|$))+/g, ""); // Remove directory traversal (../ or ..\)
Comment thread
aman19K marked this conversation as resolved.
Outdated