From d0cccb5be6d72b86c5373f139fe123044ff4c8b9 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Tue, 15 Jan 2013 01:15:08 +0300 Subject: [PATCH] Adds some more error checking to PhysicalFileSystem ctor. Fixing issues with Script/Style repo tests. --- src/Umbraco.Core/IO/PhysicalFileSystem.cs | 9 ++++++++- .../Persistence/Repositories/ScriptRepository.cs | 2 +- .../Persistence/Repositories/StylesheetRepository.cs | 2 +- .../Persistence/Repositories/ScriptRepositoryTest.cs | 4 ++-- .../Persistence/Repositories/StylesheetRepositoryTest.cs | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Core/IO/PhysicalFileSystem.cs b/src/Umbraco.Core/IO/PhysicalFileSystem.cs index fa02f39c4f..7b817ae388 100644 --- a/src/Umbraco.Core/IO/PhysicalFileSystem.cs +++ b/src/Umbraco.Core/IO/PhysicalFileSystem.cs @@ -18,7 +18,11 @@ namespace Umbraco.Core.IO public PhysicalFileSystem(string virtualRoot) { - RootPath = IOHelper.MapPath(virtualRoot); + if (virtualRoot == null) throw new ArgumentNullException("virtualRoot"); + if (!virtualRoot.StartsWith("~/")) + throw new ArgumentException("The virtualRoot argument must be a virtual path and start with '~/'"); + + RootPath = IOHelper.MapPath(virtualRoot); _rootUrl = IOHelper.ResolveUrl(virtualRoot); } @@ -30,6 +34,9 @@ namespace Umbraco.Core.IO if (string.IsNullOrEmpty(rootUrl)) throw new ArgumentException("The argument 'rootUrl' cannot be null or empty."); + if (rootPath.StartsWith("~/")) + throw new ArgumentException("The rootPath argument cannot be a virtual path and cannot start with '~/'"); + RootPath = rootPath; _rootUrl = rootUrl; } diff --git a/src/Umbraco.Core/Persistence/Repositories/ScriptRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ScriptRepository.cs index 242f8293e9..9c3fa7898a 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ScriptRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ScriptRepository.cs @@ -14,7 +14,7 @@ namespace Umbraco.Core.Persistence.Repositories /// internal class ScriptRepository : FileRepository, IScriptRepository { - public ScriptRepository(IUnitOfWork work, IFileSystem fileSystem) + internal ScriptRepository(IUnitOfWork work, IFileSystem fileSystem) : base(work, fileSystem) { } diff --git a/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs b/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs index c100ae9290..4e1ca44fb8 100644 --- a/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs @@ -14,7 +14,7 @@ namespace Umbraco.Core.Persistence.Repositories /// internal class StylesheetRepository : FileRepository, IStylesheetRepository { - public StylesheetRepository(IUnitOfWork work, IFileSystem fileSystem) + internal StylesheetRepository(IUnitOfWork work, IFileSystem fileSystem) : base(work, fileSystem) { diff --git a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs index 50de94d5ad..c594061b4e 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs @@ -17,7 +17,7 @@ namespace Umbraco.Tests.Persistence.Repositories [SetUp] public void Initialize() { - _fileSystem = new PhysicalFileSystem(SystemDirectories.Scripts, "/scripts"); + _fileSystem = new PhysicalFileSystem(SystemDirectories.Scripts); var stream = CreateStream("Umbraco.Sys.registerNamespace(\"Umbraco.Utils\");"); _fileSystem.AddFile("test-script.js", stream); } @@ -183,7 +183,7 @@ namespace Umbraco.Tests.Persistence.Repositories { _fileSystem = null; //Delete all files - var fs = new PhysicalFileSystem(SystemDirectories.Scripts, "/scripts"); + var fs = new PhysicalFileSystem(SystemDirectories.Scripts); var files = fs.GetFiles("", "*.js"); foreach (var file in files) { diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs index 4fc4cccc57..76930a98ba 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -17,7 +17,7 @@ namespace Umbraco.Tests.Persistence.Repositories [SetUp] public void Initialize() { - _fileSystem = new PhysicalFileSystem(SystemDirectories.Css, "/css"); + _fileSystem = new PhysicalFileSystem(SystemDirectories.Css); var stream = CreateStream("body {background:#EE7600; color:#FFF;}"); _fileSystem.AddFile("styles.css", stream); }