Skip to content

Commit abcd8ec

Browse files
committed
fix(Core): sanitize uploader filenames and strip protocols
Stripping protocols (https, ftp, etc.) and replacing invalid filesystem characters with underscores. This prevents uploaders like Zipline from creating accidental subdirectories when saving .sxcu files.
1 parent 15c73e6 commit abcd8ec

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

SnapX.Core/Upload/Custom/CustomUploaderItem.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public CustomUploaderItem()
148148
// };
149149
// }
150150

151-
public override string? ToString()
151+
public override string ToString()
152152
{
153153
if (!string.IsNullOrEmpty(Name))
154154
{
@@ -165,9 +165,28 @@ public CustomUploaderItem()
165165
return "Name";
166166
}
167167

168+
private static readonly string[] Protocols =
169+
[
170+
"https://", "http://", "ftp://", "sftp://", "ftps://",
171+
"smb://", "afp://", "nfs://", "ssh://", "dav://", "davs://"
172+
];
168173
public string GetFileName()
169174
{
170-
return ToString() + ".sxcu";
175+
var name = ToString();
176+
177+
foreach (var protocol in Protocols)
178+
{
179+
var index = name.IndexOf(protocol, StringComparison.OrdinalIgnoreCase);
180+
if (index != -1)
181+
{
182+
name = name.Remove(index, protocol.Length);
183+
}
184+
}
185+
186+
var invalid = Path.GetInvalidFileNameChars();
187+
name = invalid.Aggregate(name, (current, c) => current.Replace(c, '_'));
188+
189+
return name + ".sxcu";
171190
}
172191

173192
public string? GetRequestURL(CustomUploaderInput input)

0 commit comments

Comments
 (0)