Skip to content

Commit fbbad0a

Browse files
committed
modified the regex
1 parent be20526 commit fbbad0a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/contentstack-utilities/src/helpers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ export const validatePath = (input: string) => {
5353
// To escape special characters in a string
5454
export const escapeRegExp = (str: string) => str?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
5555

56-
const sanitizePathRegex = (str:string) => str?.replace(/^(\.\.(\/|\\|$))+/, '').replace(/^(\.(\/|\\|$))+/, '/')
56+
const sanitizePathRegex = (str: string) =>
57+
str
58+
?.replace(/\\/g, '/') // Convert Windows-style backslashes to forward slashes
59+
.replace(/\/+/g, '/') // Collapse multiple slashes into one
60+
.replace(/(?:^|\/)\.+(\/|$)/g, '/'); // Remove any `.` or `..` path segments
5761

5862
// To remove the relative path
5963
export const sanitizePath = (str: string) => {
6064
const decodedStr = decodeURIComponent(str);
61-
return normalize(sanitizePathRegex(decodedStr))
65+
return normalize(sanitizePathRegex(decodedStr));
6266
};
6367

6468
// To validate the UIDs of assets

0 commit comments

Comments
 (0)