From ce6ab31c32ad2b7bcce06892e985a482e54df1fe Mon Sep 17 00:00:00 2001 From: Matt <97983689+bluepilledgreat@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:38:11 +0100 Subject: [PATCH] add length check to github issue url (#3485) --- .../Elements/Dialogs/ExceptionDialog.xaml.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs index 117fb62..9301fdf 100644 --- a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs +++ b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs @@ -16,6 +16,8 @@ namespace Bloxstrap.UI.Elements.Dialogs /// public partial class ExceptionDialog { + const int MAX_GITHUB_URL_LENGTH = 8192; + public ExceptionDialog(Exception exception) { InitializeComponent(); @@ -27,12 +29,19 @@ namespace Bloxstrap.UI.Elements.Dialogs string repoUrl = $"https://github.com/{App.ProjectRepository}"; string wikiUrl = $"{repoUrl}/wiki"; - string issueUrl = String.Format( - "{0}/issues/new?template=bug_report.yaml&title={1}&log={2}", - repoUrl, - HttpUtility.UrlEncode($"[BUG] {exception.GetType()}: {exception.Message}"), - HttpUtility.UrlEncode(String.Join('\n', App.Logger.History)) - ); + string title = HttpUtility.UrlEncode($"[BUG] {exception.GetType()}: {exception.Message}"); + string log = HttpUtility.UrlEncode(String.Join('\n', App.Logger.History)); + + string issueUrl = $"{repoUrl}/issues/new?template=bug_report.yaml&title={title}&log={log}"; + + if (issueUrl.Length > MAX_GITHUB_URL_LENGTH) + { + // url is way too long for github. remove the log parameter. + issueUrl = $"{repoUrl}/issues/new?template=bug_report.yaml&title={title}"; + + if (issueUrl.Length > MAX_GITHUB_URL_LENGTH) + issueUrl = $"{repoUrl}/issues/new?template=bug_report.yaml"; // bruh + } string helpMessage = String.Format(Strings.Dialog_Exception_Info_2, wikiUrl, issueUrl);