From e1b1755fbae96245bcdd87e4adca66d91fb2bed3 Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Thu, 30 Jul 2020 16:02:00 +0300 Subject: [PATCH] Don't escape media URL on non-HTML formats --- .../Exporting/ExportContext.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/DiscordChatExporter.Domain/Exporting/ExportContext.cs b/DiscordChatExporter.Domain/Exporting/ExportContext.cs index 6c091a1..6753ef7 100644 --- a/DiscordChatExporter.Domain/Exporting/ExportContext.cs +++ b/DiscordChatExporter.Domain/Exporting/ExportContext.cs @@ -72,13 +72,17 @@ namespace DiscordChatExporter.Domain.Exporting // We want relative path so that the output files can be copied around without breaking var relativeFilePath = Path.GetRelativePath(Request.OutputBaseDirPath, filePath); - // Need to properly escape each path segment while keeping the slashes - var escapedRelativeFilePath = relativeFilePath - .Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) - .Select(Uri.EscapeDataString) - .JoinToString(Path.AltDirectorySeparatorChar.ToString()); - - return escapedRelativeFilePath; + // For HTML, we need to format the URL properly + if (Request.Format == ExportFormat.HtmlDark || Request.Format == ExportFormat.HtmlLight) + { + // Need to escape each path segment while keeping the directory separators intact + return relativeFilePath + .Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + .Select(Uri.EscapeDataString) + .JoinToString(Path.AltDirectorySeparatorChar.ToString()); + } + + return relativeFilePath; } catch (HttpRequestException) {