Add Validation FolderName to generate valid url link (#7768)

This commit is contained in:
LorenzoFrediani-Laser
2017-08-03 21:20:49 +02:00
committed by Sébastien Ros
parent bb4116dbb9
commit 2c5021f8d1

View File

@@ -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 {
bool valid = String.IsNullOrWhiteSpace(viewModel.Name) || Regex.IsMatch(viewModel.Name, @"^[^:?#\[\]@!$&'()*+,.;=\s\""\<\>\\\|%]+$");
if (!valid) {
throw new ArgumentException(T("Folder contains invalid characters").ToString());
}
else {
_mediaLibraryService.CreateFolder(viewModel.FolderPath, viewModel.Name); _mediaLibraryService.CreateFolder(viewModel.FolderPath, viewModel.Name);
Services.Notifier.Information(T("Media folder created")); 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,9 +135,15 @@ namespace Orchard.MediaLibrary.Controllers {
} }
try { try {
bool valid = String.IsNullOrWhiteSpace(viewModel.Name) || Regex.IsMatch(viewModel.Name, @"^[^:?#\[\]@!$&'()*+,.;=\s\""\<\>\\\|%]+$");
if (!valid) {
throw new ArgumentException(T("Folder contains invalid characters").ToString());
}
else {
_mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name); _mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name);
Services.Notifier.Information(T("Media folder renamed")); 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));
return View(viewModel); return View(viewModel);