-
-
Notifications
You must be signed in to change notification settings - Fork 41
Respect caller-owned invite CSV streams #759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3853,6 +3853,7 @@ internal async Task<DiscordInvite> CreateChannelInviteAsync(ulong channelId, int | |||||
| var targetUsersCsv = targetUsersFile is not null | ||||||
| ? CreateTargetUsersFile(targetUsersFile) | ||||||
| : BuildTargetUsersCsvFile(mergedTargetUsers); | ||||||
| var disposeTargetUsersCsv = targetUsersFile is null && targetUsersCsv is not null; | ||||||
|
|
||||||
| var pld = new RestChannelInviteCreatePayload | ||||||
| { | ||||||
|
|
@@ -3893,17 +3894,14 @@ internal async Task<DiscordInvite> CreateChannelInviteAsync(ulong channelId, int | |||||
| res = await this.DoRequestAsync(this.Discord, bucket, url, RestRequestMethod.POST, route, headers, DiscordJson.SerializeObject(pld)).ConfigureAwait(false); | ||||||
| } | ||||||
|
|
||||||
| if (targetUsersCsv?.ResetPositionTo is not null) | ||||||
| targetUsersCsv.Stream.Position = targetUsersCsv.ResetPositionTo.Value; | ||||||
|
|
||||||
| var ret = DiscordJson.DeserializeObject<DiscordInvite>(res.Response, this.Discord); | ||||||
| ret.Discord = this.Discord; | ||||||
|
|
||||||
| if (targetUsersCsv is not null && targetUsersCsv.ResetPositionTo is null) | ||||||
| if (disposeTargetUsersCsv) | ||||||
| { | ||||||
|
Comment on lines
3897
to
3901
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||||||
| try | ||||||
| { | ||||||
| targetUsersCsv.Stream.Dispose(); | ||||||
| targetUsersCsv?.Stream.Dispose(); | ||||||
|
||||||
| targetUsersCsv?.Stream.Dispose(); | |
| targetUsersCsv.Stream.Dispose(); |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null check targetUsersCsv is not null is redundant. At this point in the code flow, targetUsersCsv is guaranteed to be non-null because line 5139 throws an ArgumentException if it's null. The condition can be simplified to just checking targetUsersCsv.ResetPositionTo is not null.
| if (targetUsersCsv is not null && targetUsersCsv.ResetPositionTo is not null) | |
| if (targetUsersCsv.ResetPositionTo is not null) |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null-conditional operator on targetUsersCsv?.Stream.Dispose() is redundant. The outer condition if (disposeTargetUsersCsv) already ensures targetUsersCsv is not null because disposeTargetUsersCsv is only true when targetUsersFile is null && targetUsersCsv is not null. You can safely use targetUsersCsv.Stream.Dispose() instead.
| targetUsersCsv?.Stream.Dispose(); | |
| targetUsersCsv.Stream.Dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The
CreateChannelInviteAsyncmethod fails to restore the original position of a caller-provided stream intargetUsersCsv, leaving it at an unexpected position after the operation completes.Severity: MEDIUM
Suggested Fix
Reintroduce the stream position reset logic in
CreateChannelInviteAsyncbefore the method exits. Add back the checkif (targetUsersCsv?.ResetPositionTo is not null) targetUsersCsv.Stream.Position = targetUsersCsv.ResetPositionTo.Value;to ensure the stream's position is restored for caller-owned streams, mirroring the implementation inUpdateInviteTargetUsersAsync.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.