Skip to content

Commit

Permalink
Use the URI comparer to fix #35
Browse files Browse the repository at this point in the history
  • Loading branch information
fubar-coder committed Dec 1, 2021
1 parent 5b8b688 commit e4cd8a3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static IServiceCollection AddWebDav(
services.TryAddSingleton<ISystemClock, SystemClock>();
services.TryAddSingleton<ITimeoutPolicy, DefaultTimeoutPolicy>();
services.TryAddSingleton<IWebDavContextAccessor, WebDavContextAccessor>();
services.TryAddScoped<IUriComparer, DefaultUriComparer>();
services.TryAddSingleton<IPathTraversalEngine, PathTraversalEngine>();
services.TryAddSingleton<IMimeTypeDetector, DefaultMimeTypeDetector>();
services.TryAddSingleton<IEntryPropertyInitializer, DefaultEntryPropertyInitializer>();
Expand Down
12 changes: 10 additions & 2 deletions src/FubarDev.WebDavServer/Handlers/Impl/CopyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,23 @@ public class CopyHandler : CopyMoveHandlerBase, ICopyHandler
/// <param name="litmusCompatibilityOptions">Options for the compatibility with the litmus tool.</param>
/// <param name="logger">The logger for this handler.</param>
/// <param name="serviceProvider">The service provider used to lazily query the <see cref="IRemoteCopyTargetActionsFactory"/> implementation.</param>
/// <param name="uriComparer">The comparer for URIs.</param>
public CopyHandler(
IFileSystem rootFileSystem,
IWebDavContextAccessor contextAccessor,
IImplicitLockFactory implicitLockFactory,
IOptions<CopyHandlerOptions> options,
IOptions<LitmusCompatibilityOptions> litmusCompatibilityOptions,
ILogger<CopyHandler> logger,
IServiceProvider serviceProvider)
: base(rootFileSystem, contextAccessor, implicitLockFactory, litmusCompatibilityOptions, logger)
IServiceProvider serviceProvider,
IUriComparer? uriComparer = default)
: base(
rootFileSystem,
contextAccessor,
implicitLockFactory,
litmusCompatibilityOptions,
logger,
uriComparer)
{
_serviceProvider = serviceProvider;
_options = options.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public abstract class CopyMoveHandlerBase
private readonly IWebDavContextAccessor _contextAccessor;

private readonly IImplicitLockFactory _implicitLockFactory;
private readonly IUriComparer? _uriComparer;

private readonly LitmusCompatibilityOptions _litmusCompatibilityOptions;

Expand All @@ -43,16 +44,19 @@ public abstract class CopyMoveHandlerBase
/// <param name="implicitLockFactory">A factory to create implicit locks.</param>
/// <param name="litmusCompatibilityOptions">Options for the compatibility with the litmus tool.</param>
/// <param name="logger">The logger to use (either for COPY or MOVE).</param>
/// <param name="uriComparer">The comparer for URIs.</param>
protected CopyMoveHandlerBase(
IFileSystem rootFileSystem,
IWebDavContextAccessor contextAccessor,
IImplicitLockFactory implicitLockFactory,
IOptions<LitmusCompatibilityOptions> litmusCompatibilityOptions,
ILogger logger)
ILogger logger,
IUriComparer? uriComparer = null)
{
_rootFileSystem = rootFileSystem;
_contextAccessor = contextAccessor;
_implicitLockFactory = implicitLockFactory;
_uriComparer = uriComparer;
_litmusCompatibilityOptions = litmusCompatibilityOptions.Value;
Logger = logger;
}
Expand Down Expand Up @@ -132,9 +136,10 @@ await WebDavContext.RequestHeaders
{
var sourceUrl = WebDavContext.PublicAbsoluteRequestUrl;
var destinationUrl = new Uri(sourceUrl, destination);
var uriComparer = _uriComparer ?? new DefaultUriComparer(_contextAccessor);

// Ignore different schemes
if (!WebDavContext.PublicControllerUrl.IsBaseOf(destinationUrl) || mode == RecursiveProcessingMode.PreferCrossServer)
if (!uriComparer.IsThisServer(destinationUrl) || mode == RecursiveProcessingMode.PreferCrossServer)
{
if (Logger.IsEnabled(LogLevel.Trace))
{
Expand Down
12 changes: 10 additions & 2 deletions src/FubarDev.WebDavServer/Handlers/Impl/MoveHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,23 @@ public class MoveHandler : CopyMoveHandlerBase, IMoveHandler
/// <param name="litmusCompatibilityOptions">Options for the compatibility with the litmus tool.</param>
/// <param name="logger">The logger for this handler.</param>
/// <param name="serviceProvider">The service provider used to lazily query the <see cref="IRemoteMoveTargetActionsFactory"/> implementation.</param>
/// <param name="uriComparer">The comparer for URIs.</param>
public MoveHandler(
IFileSystem rootFileSystem,
IWebDavContextAccessor contextAccessor,
IImplicitLockFactory implicitLockFactory,
IOptions<MoveHandlerOptions> options,
IOptions<LitmusCompatibilityOptions> litmusCompatibilityOptions,
ILogger<MoveHandler> logger,
IServiceProvider serviceProvider)
: base(rootFileSystem, contextAccessor, implicitLockFactory, litmusCompatibilityOptions, logger)
IServiceProvider serviceProvider,
IUriComparer? uriComparer = null)
: base(
rootFileSystem,
contextAccessor,
implicitLockFactory,
litmusCompatibilityOptions,
logger,
uriComparer)
{
_serviceProvider = serviceProvider;
_options = options.Value;
Expand Down

0 comments on commit e4cd8a3

Please sign in to comment.