Skip to content

Commit 84990c3

Browse files
committedFeb 24, 2025··
Allow multiple values for one key when adding web request parameters
Couldn't be me fixing this for FILE parameters (ppy#6412) and then completely failing to notice that `AddParameter()` in fact *OVERWRITES* the previous value for a given key. This failure is the root cause for ppy/osu#32059. The difference between the online version of the beatmap and the local version provided by the user is that two `.osu` files changed filename inadvertently, because of lazer escaping quote characters (which stable doesn't do). In terms of patching, submission represents this as deleting the two files from the online version of the package and then adding another two. However, because `AddParameter()` would silently *ONLY KEEP THE LAST FILENAME SPECIFIED* to delete, one of the `.osu` files would remain in the patched package, and show up as a "tag mismatch" while it was supposed to be completely gone. --- ## Breaking changes `WebRequest.AddParameter()` multiple times with the same first parameter (`name`) will no longer overwrite previous calls, which is to say, a single parameter name is allowed to be associated with multiple values.
1 parent b312ac3 commit 84990c3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed
 

‎osu.Framework/IO/Network/WebRequest.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ public class WebRequest : IDisposable
109109
/// <summary>
110110
/// Query string parameters.
111111
/// </summary>
112-
private readonly Dictionary<string, string> queryParameters = new Dictionary<string, string>();
112+
private readonly List<(string key, string value)> queryParameters = new List<(string key, string value)>();
113113

114114
/// <summary>
115115
/// Form parameters.
116116
/// </summary>
117-
private readonly Dictionary<string, string> formParameters = new Dictionary<string, string>();
117+
private readonly List<(string key, string value)> formParameters = new List<(string key, string value)>();
118118

119119
/// <summary>
120120
/// FILE parameters.
@@ -304,7 +304,7 @@ private async Task internalPerform(CancellationToken cancellationToken = default
304304

305305
StringBuilder requestParameters = new StringBuilder();
306306
foreach (var p in queryParameters)
307-
requestParameters.Append($@"{p.Key}={Uri.EscapeDataString(p.Value)}&");
307+
requestParameters.Append($"{p.key}={Uri.EscapeDataString(p.value)}&");
308308
string requestString = requestParameters.ToString().TrimEnd('&');
309309
url = string.IsNullOrEmpty(requestString) ? url : $"{url}?{requestString}";
310310

@@ -345,7 +345,7 @@ private async Task internalPerform(CancellationToken cancellationToken = default
345345
var formData = new MultipartFormDataContent(form_boundary);
346346

347347
foreach (var p in formParameters)
348-
formData.Add(new StringContent(p.Value), p.Key);
348+
formData.Add(new StringContent(p.value), p.key);
349349

350350
foreach (var p in files)
351351
{
@@ -681,7 +681,7 @@ public void AddFile(string paramName, byte[] data, string filename = "blob")
681681

682682
/// <summary>
683683
/// <para>
684-
/// Add a new parameter to this request. Replaces any existing parameter with the same name.
684+
/// Add a new parameter to this request.
685685
/// </para>
686686
/// <para>
687687
/// If this request's <see cref="Method"/> supports a request body (<c>POST, PUT, DELETE, PATCH</c>), a <see cref="RequestParameterType.Form"/> parameter will be added;
@@ -701,7 +701,7 @@ public void AddParameter(string name, string value)
701701
=> AddParameter(name, value, supportsRequestBody(Method) ? RequestParameterType.Form : RequestParameterType.Query);
702702

703703
/// <summary>
704-
/// Add a new parameter to this request. Replaces any existing parameter with the same name.
704+
/// Add a new parameter to this request.
705705
/// <see cref="RequestParameterType.Form"/> parameters may not be used in conjunction with <see cref="AddRaw(Stream)"/>.
706706
/// </summary>
707707
/// <remarks>
@@ -718,14 +718,14 @@ public void AddParameter(string name, string value, RequestParameterType type)
718718
switch (type)
719719
{
720720
case RequestParameterType.Query:
721-
queryParameters[name] = value;
721+
queryParameters.Add((name, value));
722722
break;
723723

724724
case RequestParameterType.Form:
725725
if (!supportsRequestBody(Method))
726726
throw new ArgumentException("Cannot add form parameter to a request type which has no body.", nameof(type));
727727

728-
formParameters[name] = value;
728+
formParameters.Add((name, value));
729729
break;
730730
}
731731
}

0 commit comments

Comments
 (0)
Please sign in to comment.