Skip to content

Commit

Permalink
[Fix] URL encode timestamps sent as query parameters (#2770)
Browse files Browse the repository at this point in the history
* [Fix] URL encode timestamps sent as query parameters
  • Loading branch information
Sauceke authored Sep 2, 2023
1 parent 75cf622 commit 589c58a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Discord.Net.Rest/DiscordRestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,13 @@ public async Task<ChannelThreads> GetPublicArchivedThreadsAsync(ulong channelId,

if (limit.HasValue)
{
query = $"?before={before.GetValueOrDefault(DateTimeOffset.UtcNow).ToString("O")}&limit={limit.Value}";
string beforeEncoded = WebUtility.UrlEncode(before.GetValueOrDefault(DateTimeOffset.UtcNow).ToString("O"));
query = $"?before={beforeEncoded}&limit={limit.Value}";
}
else if (before.HasValue)
{
query = $"?before={before.Value.ToString("O")}";
string beforeEncoded = WebUtility.UrlEncode(before.Value.ToString("O"));
query = $"?before={beforeEncoded}";
}

return await SendAsync<ChannelThreads>("GET", () => $"channels/{channelId}/threads/archived/public{query}", bucket, options: options);
Expand All @@ -641,11 +643,13 @@ public async Task<ChannelThreads> GetPrivateArchivedThreadsAsync(ulong channelId

if (limit.HasValue)
{
query = $"?before={before.GetValueOrDefault(DateTimeOffset.UtcNow).ToString("O")}&limit={limit.Value}";
string beforeEncoded = WebUtility.UrlEncode(before.GetValueOrDefault(DateTimeOffset.UtcNow).ToString("O"));
query = $"?before={beforeEncoded}&limit={limit.Value}";
}
else if (before.HasValue)
{
query = $"?before={before.Value.ToString("O")}";
string beforeEncoded = WebUtility.UrlEncode(before.Value.ToString("O"));
query = $"?before={beforeEncoded}";
}

return await SendAsync<ChannelThreads>("GET", () => $"channels/{channelId}/threads/archived/private{query}", bucket, options: options);
Expand Down

0 comments on commit 589c58a

Please sign in to comment.