mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-25 10:59:18 +08:00
Add Validation FolderName to generate valid url link (#7768)
This commit is contained in:
committed by
Sébastien Ros
parent
bb4116dbb9
commit
2c5021f8d1
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
@@ -67,17 +68,21 @@ namespace Orchard.MediaLibrary.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_mediaLibraryService.CreateFolder(viewModel.FolderPath, viewModel.Name);
|
bool valid = String.IsNullOrWhiteSpace(viewModel.Name) || Regex.IsMatch(viewModel.Name, @"^[^:?#\[\]@!$&'()*+,.;=\s\""\<\>\\\|%]+$");
|
||||||
Services.Notifier.Information(T("Media folder created"));
|
if (!valid) {
|
||||||
|
throw new ArgumentException(T("Folder contains invalid characters").ToString());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_mediaLibraryService.CreateFolder(viewModel.FolderPath, viewModel.Name);
|
||||||
|
Services.Notifier.Information(T("Media folder created"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (ArgumentException argumentException) {
|
catch (ArgumentException argumentException) {
|
||||||
Services.Notifier.Error(T("Creating Folder failed: {0}", argumentException.Message));
|
Services.Notifier.Error(T("Creating Folder failed: {0}", argumentException.Message));
|
||||||
Services.TransactionManager.Cancel();
|
Services.TransactionManager.Cancel();
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedirectToAction("Index", "Admin", new { area = "Orchard.MediaLibrary" });
|
return RedirectToAction("Index", "Admin", new { area = "Orchard.MediaLibrary" });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Edit(string folderPath) {
|
public ActionResult Edit(string folderPath) {
|
||||||
@@ -130,8 +135,14 @@ namespace Orchard.MediaLibrary.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name);
|
bool valid = String.IsNullOrWhiteSpace(viewModel.Name) || Regex.IsMatch(viewModel.Name, @"^[^:?#\[\]@!$&'()*+,.;=\s\""\<\>\\\|%]+$");
|
||||||
Services.Notifier.Information(T("Media folder renamed"));
|
if (!valid) {
|
||||||
|
throw new ArgumentException(T("Folder contains invalid characters").ToString());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name);
|
||||||
|
Services.Notifier.Information(T("Media folder renamed"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
Services.Notifier.Error(T("Editing Folder failed: {0}", exception.Message));
|
Services.Notifier.Error(T("Editing Folder failed: {0}", exception.Message));
|
||||||
|
|||||||
Reference in New Issue
Block a user