diff --git a/GUI/CrashForm.cs b/GUI/CrashForm.cs index 60c5aa4..6560609 100644 --- a/GUI/CrashForm.cs +++ b/GUI/CrashForm.cs @@ -4,11 +4,11 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2009-2010 Michael Möller + Copyright (C) 2009-2020 Michael Möller */ - +using OpenHardwareMonitor.Utilities; using System; using System.IO; using System.Net; @@ -59,10 +59,10 @@ namespace OpenHardwareMonitor.GUI { string report = "type=crash&" + - "version=" + Uri.EscapeDataString(version.ToString()) + "&" + - "report=" + Uri.EscapeDataString(reportTextBox.Text) + "&" + - "comment=" + Uri.EscapeDataString(commentTextBox.Text) + "&" + - "email=" + Uri.EscapeDataString(emailTextBox.Text); + "version=" + HttpUtility.UrlEncode(version.ToString()) + "&" + + "report=" + HttpUtility.UrlEncode(reportTextBox.Text) + "&" + + "comment=" + HttpUtility.UrlEncode(commentTextBox.Text) + "&" + + "email=" + HttpUtility.UrlEncode(emailTextBox.Text); byte[] byteArray = Encoding.UTF8.GetBytes(report); request.ContentLength = byteArray.Length; diff --git a/GUI/ReportForm.cs b/GUI/ReportForm.cs index e61c053..c0de8c1 100644 --- a/GUI/ReportForm.cs +++ b/GUI/ReportForm.cs @@ -4,10 +4,11 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2009-2010 Michael Möller + Copyright (C) 2009-2020 Michael Möller */ +using OpenHardwareMonitor.Utilities; using System; using System.Drawing; using System.IO; @@ -47,10 +48,10 @@ namespace OpenHardwareMonitor.GUI { string report = "type=hardware&" + - "version=" + Uri.EscapeDataString(version.ToString()) + "&" + - "report=" + Uri.EscapeDataString(reportTextBox.Text) + "&" + - "comment=" + Uri.EscapeDataString(commentTextBox.Text) + "&" + - "email=" + Uri.EscapeDataString(emailTextBox.Text); + "version=" + HttpUtility.UrlEncode(version.ToString()) + "&" + + "report=" + HttpUtility.UrlEncode(reportTextBox.Text) + "&" + + "comment=" + HttpUtility.UrlEncode(commentTextBox.Text) + "&" + + "email=" + HttpUtility.UrlEncode(emailTextBox.Text); byte[] byteArray = Encoding.UTF8.GetBytes(report); request.ContentLength = byteArray.Length; diff --git a/OpenHardwareMonitor.csproj b/OpenHardwareMonitor.csproj index 35e749b..03561a1 100644 --- a/OpenHardwareMonitor.csproj +++ b/OpenHardwareMonitor.csproj @@ -125,6 +125,7 @@ + diff --git a/Utilities/HttpUtility.cs b/Utilities/HttpUtility.cs new file mode 100644 index 0000000..98077aa --- /dev/null +++ b/Utilities/HttpUtility.cs @@ -0,0 +1,34 @@ +/* + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + + Copyright (C) 2020 Michael Möller + +*/ + +using System; +using System.Text; + +namespace OpenHardwareMonitor.Utilities { + + public class HttpUtility { + public static string UrlEncode(string s) { + + int maxLength = 32765; + var sb = new StringBuilder(); + int imax = s.Length / maxLength; + + for (int i = 0; i <= imax; i++) { + sb.Append( + Uri.EscapeDataString(i < imax + ? s.Substring(maxLength * i, maxLength) + : s.Substring(maxLength * i))); + } + + return sb.ToString(); + } + + } +}