Skip to content

Commit 6644502

Browse files
committed
fix: Handle null keys in Query Parameter Building
1 parent 017bce1 commit 6644502

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Runtime/Client/EndPointClass.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,47 @@ public EndPointClass(string endPoint, LootLockerHTTPMethod httpMethod, LootLocke
2828
public string WithPathParameter(object arg0)
2929
{
3030
try {
31-
return string.Format(endPoint, WebUtility.UrlEncode(arg0.ToString()));
31+
return string.Format(endPoint, WebUtility.UrlEncode(arg0?.ToString() ?? "null"));
3232
}
3333
catch (FormatException e)
3434
{
35-
LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameter \"{WebUtility.UrlEncode(arg0.ToString())}\": {e}", LootLockerLogger.LogLevel.Error);
35+
LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameter \"{WebUtility.UrlEncode(arg0?.ToString() ?? "null")}\": {e}", LootLockerLogger.LogLevel.Error);
3636
return endPoint;
3737
}
3838
}
3939

4040
public string WithPathParameters(object arg0, object arg1)
4141
{
4242
try {
43-
return string.Format(endPoint, WebUtility.UrlEncode(arg0.ToString()), WebUtility.UrlEncode(arg1.ToString()));
43+
return string.Format(endPoint, WebUtility.UrlEncode(arg0?.ToString() ?? "null"), WebUtility.UrlEncode(arg1?.ToString() ?? "null"));
4444
}
4545
catch (FormatException e)
4646
{
47-
LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameters \"{WebUtility.UrlEncode(arg0.ToString())}\", \"{WebUtility.UrlEncode(arg1.ToString())}\": {e}", LootLockerLogger.LogLevel.Error);
47+
LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameters \"{WebUtility.UrlEncode(arg0?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg1?.ToString() ?? "null")}\": {e}", LootLockerLogger.LogLevel.Error);
4848
return endPoint;
4949
}
5050
}
5151

5252
public string WithPathParameters(object arg0, object arg1, object arg2)
5353
{
5454
try {
55-
return string.Format(endPoint, WebUtility.UrlEncode(arg0.ToString()), WebUtility.UrlEncode(arg1.ToString()), WebUtility.UrlEncode(arg2.ToString()));
55+
return string.Format(endPoint, WebUtility.UrlEncode(arg0?.ToString() ?? "null"), WebUtility.UrlEncode(arg1?.ToString() ?? "null"), WebUtility.UrlEncode(arg2?.ToString() ?? "null"));
5656
}
5757
catch (FormatException e)
5858
{
59-
LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameters \"{WebUtility.UrlEncode(arg0.ToString())}\", \"{WebUtility.UrlEncode(arg1.ToString())}\", \"{WebUtility.UrlEncode(arg2.ToString())}\": {e}", LootLockerLogger.LogLevel.Error);
59+
LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameters \"{WebUtility.UrlEncode(arg0?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg1?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg2?.ToString() ?? "null")}\": {e}", LootLockerLogger.LogLevel.Error);
6060
return endPoint;
6161
}
6262
}
6363

6464
public string WithPathParameters(object arg0, object arg1, object arg2, object arg3)
6565
{
6666
try {
67-
return string.Format(endPoint, WebUtility.UrlEncode(arg0.ToString()), WebUtility.UrlEncode(arg1.ToString()), WebUtility.UrlEncode(arg2.ToString()), WebUtility.UrlEncode(arg3.ToString()));
67+
return string.Format(endPoint, WebUtility.UrlEncode(arg0?.ToString() ?? "null"), WebUtility.UrlEncode(arg1?.ToString() ?? "null"), WebUtility.UrlEncode(arg2?.ToString() ?? "null"), WebUtility.UrlEncode(arg3?.ToString() ?? "null"));
6868
}
6969
catch (FormatException e)
7070
{
71-
LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameters \"{WebUtility.UrlEncode(arg0.ToString())}\", \"{WebUtility.UrlEncode(arg1.ToString())}\", \"{WebUtility.UrlEncode(arg2.ToString())}\", \"{WebUtility.UrlEncode(arg3.ToString())}\": {e}", LootLockerLogger.LogLevel.Error);
71+
LootLockerLogger.Log($"Error formatting endpoint \"{endPoint}\" with path parameters \"{WebUtility.UrlEncode(arg0?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg1?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg2?.ToString() ?? "null")}\", \"{WebUtility.UrlEncode(arg3?.ToString() ?? "null")}\": {e}", LootLockerLogger.LogLevel.Error);
7272
return endPoint;
7373
}
7474
}

Runtime/Client/LootLockerHTTPClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ private void CallListenersAndMarkDone(LootLockerHTTPExecutionQueueItem execution
566566
executionItem.Done = true;
567567
response.requestContext = new LootLockerRequestContext(executionItem.RequestData.ForPlayerWithUlid, executionItem.RequestData.RequestStartTime);
568568
executionItem.Response = response;
569-
if(!CompletedRequestIDs.Contains(executionItem.RequestData.RequestId)) {
569+
if (!CompletedRequestIDs.Contains(executionItem.RequestData.RequestId))
570+
{
570571
CompletedRequestIDs.Add(executionItem.RequestData.RequestId);
571572
}
572573
executionItem.RequestData.CallListenersWithResult(response);

Runtime/Game/Utilities/LootLockerHttpUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public string Build()
5959

6060
foreach (KeyValuePair<string, string> pair in _queryParams)
6161
{
62-
if (string.IsNullOrEmpty(pair.Value))
62+
if (string.IsNullOrEmpty(pair.Key) || string.IsNullOrEmpty(pair.Value))
6363
continue;
6464

6565
if (query.Length > 1)

0 commit comments

Comments
 (0)