From f9c0b86a7acef746f783bc1a2b6067654905851d Mon Sep 17 00:00:00 2001 From: Matt Trussler Date: Thu, 23 Jul 2020 17:26:04 +0200 Subject: [PATCH] Fix relative path url generation (#129) All bundle paths seem to end up starting with a "/" which is absolute as far as Path.Combine is concerned. When combining with wwwroot the full path gets lost and the incorrect url gets generated. Removing the '/' at the start of the asset fixes this issue --- src/WebOptimizer.Core/Processors/RelativePathAdjuster.cs | 2 +- .../Processors/RelativePathAdjusterTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WebOptimizer.Core/Processors/RelativePathAdjuster.cs b/src/WebOptimizer.Core/Processors/RelativePathAdjuster.cs index bdd1602..66a9ad1 100644 --- a/src/WebOptimizer.Core/Processors/RelativePathAdjuster.cs +++ b/src/WebOptimizer.Core/Processors/RelativePathAdjuster.cs @@ -25,7 +25,7 @@ public override Task ExecuteAsync(IAssetContext config) foreach (string key in config.Content.Keys) { IFileInfo input = fileProvider.GetFileInfo(key); - string outputPath = Path.Combine(env.WebRootPath, config.Asset.Route); + string outputPath = Path.Combine(env.WebRootPath, config.Asset.Route.TrimStart('/')); content[key] = Adjust(config.Content[key].AsString(), input.PhysicalPath, outputPath); } diff --git a/test/WebOptimizer.Core.Test/Processors/RelativePathAdjusterTest.cs b/test/WebOptimizer.Core.Test/Processors/RelativePathAdjusterTest.cs index f16e309..ffde580 100644 --- a/test/WebOptimizer.Core.Test/Processors/RelativePathAdjusterTest.cs +++ b/test/WebOptimizer.Core.Test/Processors/RelativePathAdjusterTest.cs @@ -34,7 +34,7 @@ public async Task AdjustRelativePaths_Success(string url, string newUrl) .Returns(@"//source"); context.SetupGet(s => s.Asset.Route) - .Returns(@"dist/all.css"); + .Returns(@"/dist/all.css"); context.Setup(s => s.HttpContext.RequestServices.GetService(typeof(IAssetPipeline))) .Returns(pipeline.Object);