File tree Expand file tree Collapse file tree 1 file changed +13
-16
lines changed
Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -27,24 +27,21 @@ def sanitise_nonpath(in_string: str) -> str:
2727
2828
2929def secure_path (in_path : Path , keep_spaces : bool = False ) -> Path :
30- if keep_spaces :
31- secured_parts = []
32- for p , part in enumerate (in_path .parts ):
30+ secured_parts = []
31+ for p , part in enumerate (in_path .parts ):
32+ if p == 0 and ":" in part :
33+ secured_parts .append (secure_filename (part ) + ":" )
34+ continue # Skip subsequent conditions and move to next part
35+ if keep_spaces :
3336 if " " in part :
3437 secured_parts .append (part )
35- elif ":" in part and not p :
36- secured_parts .append (secure_filename (part ) + ":" )
37- else :
38- secured_parts .append (secure_filename (part ))
39- else :
40- secured_parts = [
41- (
42- secure_filename (part ) + ":"
43- if p == 0 and ":" in part
44- else secure_filename (part )
45- )
46- for p , part in enumerate (in_path .parts )
47- ]
38+ continue # Skip subsequent conditions and move to next part
39+ if part .endswith ("_" ):
40+ # Preserve all trailing underscores
41+ num_underscores = len (part ) - len (part .rstrip ("_" ))
42+ secured_parts .append (secure_filename (part ) + (num_underscores * "_" ))
43+ else :
44+ secured_parts .append (secure_filename (part ))
4845 return Path ("/" .join (secured_parts ))
4946
5047
You can’t perform that action at this time.
0 commit comments