Fix URL-safe encoding of uploaded filenames
Replace the fragment marker used for unsupported filename characters with an underscore and cover upload metadata and static-file downloads. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
446b595077
commit
2765d3eef8
3 changed files with 88 additions and 8 deletions
|
|
@ -49,6 +49,7 @@ namespace Yavsc.Server.Helpers
|
|||
// Ensure this path is canonical,
|
||||
// No "dirto/./this", neither "dirt/to/that/"
|
||||
// no .. and each char must be listed as valid in constants
|
||||
// Encode unsupported chars with '_' rather than the URL fragment marker '#'.
|
||||
public static string FilterFileName(string fileName)
|
||||
{
|
||||
if (fileName==null) return null;
|
||||
|
|
@ -57,7 +58,7 @@ namespace Yavsc.Server.Helpers
|
|||
{
|
||||
if (ValidFileNameChars.Contains(c))
|
||||
sb.Append(c);
|
||||
else sb.Append("#" + ((int)c).ToString("D3"));
|
||||
else sb.Append("_" + ((int)c).ToString("D3"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue