Skip to content

Conversation

@colindcli
Copy link

  1. cookie.Name cannot be assigned an empty string.
  2. cookie.Value containing comma-separated JSON strings will be truncated into multiple key-value pairs.

cookie string like this:

" "; Location={"country":"","city":" "}

1. `cookie.Name` cannot be assigned an empty string.
2. `cookie.Value` containing comma-separated JSON strings will be truncated into multiple key-value pairs.

cookie string like this:
" "; Location={"country":"","city":" "}
@gemini-code-assist
Copy link

Summary of Changes

Hello @colindcli, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses and resolves critical bugs within the HttpListenerRequest's cookie parsing mechanism. The primary goal was to ensure accurate interpretation of cookie headers, particularly those with complex values like comma-separated JSON strings, which were previously being incorrectly truncated. The changes enhance the robustness of cookie handling and are thoroughly validated by a new suite of unit tests.

Highlights

  • Cookie Parsing Logic Refinement: The ParseCookies method has been refactored to be a static method that returns a CookieList, improving its reusability and testability. It now correctly handles cookie values that contain commas, preventing unintended truncation of data such as JSON strings.
  • Robust Error Handling: Improved resilience against malformed cookie strings by wrapping the cookie creation logic in a try-catch block, ensuring that parsing continues gracefully even if individual cookie parts are invalid.
  • Comprehensive Unit Testing: A new dedicated test file, HttpListenerRequestCookieTest.cs, has been added with extensive unit tests covering various cookie parsing scenarios, including edge cases like quoted values, name-only cookies, and the specific JSON value parsing issue.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a bug in cookie parsing where values containing commas (like JSON) were incorrectly split. The change to split cookie strings only by semicolons is correct and is well-supported by the new unit tests. The logic to handle invalid cookie parts by catching exceptions is also a good addition.

I've provided a couple of suggestions for improvement:

  • Make the exception handling for invalid cookies more specific to avoid catching unrelated errors.
  • Correct a new test case that was asserting incorrect behavior for an invalid cookie name.

Overall, this is a good fix that improves the robustness of cookie parsing.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses cookie parsing issues in HttpListenerRequest: preventing empty-name cookies and avoiding truncation of JSON values containing commas. It adds unit tests and refactors the parser to return a CookieList, splitting only on semicolons to preserve JSON commas and quoting the $Port attribute.

  • Refactors ParseCookies to static method returning CookieList and adjusts header handling to use its result.
  • Updates cookie tokenization to split only by semicolons; trims tokens and preserves quoted values and JSON.
  • Adds comprehensive tests covering version/attributes application, name-only cookies, quoted values, JSON, and port quoting.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/EmbedIO/Net/Internal/HttpListenerRequest.cs Refactors cookie parsing to return CookieList, changes splitting to semicolons, quotes $Port, and assigns parsed cookies in AddHeader.
test/EmbedIO.Tests/Utilities/HttpListenerRequestCookieTest.cs Adds tests verifying cookie parsing behavior, including JSON value preservation and handling of quoted names/values and attributes.
Comments suppressed due to low confidence (1)

src/EmbedIO/Net/Internal/HttpListenerRequest.cs:462

  • This assignment to e is useless, since its value is never read.
                    catch (Exception e)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

There is a problem with the calculation when the URL uses the default port.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

Comments suppressed due to low confidence (1)

src/EmbedIO/Net/Internal/HttpListenerRequest.cs:462

  • This assignment to e is useless, since its value is never read.
                    catch (Exception e)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant