Skip to content

Commit

Permalink
The default date format is yyyyMMddhhmmss if not specified.
Browse files Browse the repository at this point in the history
The exception message for not secure relative path is more clear now.
  • Loading branch information
VictorTomaili committed Jan 24, 2024
1 parent 4cef806 commit 64c5bf5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Serenity.Net.Core/Helpers/PathHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;

namespace Serenity;

Expand Down Expand Up @@ -47,7 +47,7 @@ public static string SecureCombine(string root, string relativePath)
throw new ArgumentNullException(nameof(relativePath));

if (relativePath.Length > 0 && !IsSecureRelativePath(relativePath))
throw new ArgumentOutOfRangeException(nameof(relativePath));
throw new ArgumentOutOfRangeException(nameof(relativePath), "Invalid characters in path!");

return Path.Combine(root, relativePath);
}
Expand Down
8 changes: 6 additions & 2 deletions src/Serenity.Net.Services/Upload/UploadFormatting.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Serenity.IO;
using Serenity.IO;
using Path = System.IO.Path;

namespace Serenity.Web;
Expand Down Expand Up @@ -44,7 +44,11 @@ public static string FormatFilename(FormatFilenameOptions options)
if (string.IsNullOrEmpty(originalName))
throw new ArgumentNullException(nameof(originalName));

var formatted = string.Format(options.Format, identity, groupKey,
var formatted = options.Format;
if (formatted.Contains("{3}", StringComparison.OrdinalIgnoreCase))
formatted = formatted.Replace("{3}", "{3:yyyyMMddhhmmss}");

formatted = string.Format(formatted, identity, groupKey,
TemporaryFileHelper.RandomFileCode(), DateTime.Now,
Path.GetFileNameWithoutExtension(originalName)) + Path.GetExtension(options.OriginalName);

Expand Down

0 comments on commit 64c5bf5

Please sign in to comment.