-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing that renaming Media Library files to a reserved Windows name should cause an error, fixes #6802 #6919
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
using System; | ||
using System.IO; | ||
using System.Runtime.Serialization; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unnecessary using |
||
using System.Text.RegularExpressions; | ||
using NHibernate.Hql; | ||
using Orchard.Environment; | ||
|
||
namespace Orchard.Validation { | ||
/// <summary> | ||
/// Provides methods to validate paths. | ||
/// </summary> | ||
public static class PathValidation { | ||
|
||
/// <summary> | ||
/// Determines if a path lies within the base path boundaries. | ||
/// If not, an exception is thrown. | ||
|
@@ -26,10 +31,22 @@ public static string ValidatePath(string basePath, string mappedPath) { | |
} | ||
|
||
if (!valid) { | ||
throw new ArgumentException("Invalid path"); | ||
if (System.Environment.OSVersion.Platform == PlatformID.Win32NT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to check the environment |
||
throw new InvalidWindowsPathException("Invalid path"); | ||
else | ||
throw new ArgumentException("Invalid path"); | ||
} | ||
|
||
return mappedPath; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Thrown when an invalid path is encountered on a Windows platform. | ||
/// </summary> | ||
[Serializable] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary as we can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throwing OrchardException breaks unit testOrchard.Framework.Tests.Orchard.Tests.Storage.FileStystemStorageProviderTests.CreateFileFailsInInvalidPath. |
||
public class InvalidWindowsPathException : ApplicationException { | ||
public InvalidWindowsPathException(string message) : base(message) { | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use
OrchardException
here.