File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
packages/contentstack-utilities/src Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -53,12 +53,16 @@ export const validatePath = (input: string) => {
53
53
// To escape special characters in a string
54
54
export const escapeRegExp = ( str : string ) => str ?. replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ;
55
55
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
57
61
58
62
// To remove the relative path
59
63
export const sanitizePath = ( str : string ) => {
60
64
const decodedStr = decodeURIComponent ( str ) ;
61
- return normalize ( sanitizePathRegex ( decodedStr ) )
65
+ return normalize ( sanitizePathRegex ( decodedStr ) ) ;
62
66
} ;
63
67
64
68
// To validate the UIDs of assets
You can’t perform that action at this time.
0 commit comments