Skip to content
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

[dotnet] Annotate nullability on SendingRemoteHttpRequestEventArgs #15148

Merged
merged 2 commits into from
Jan 24, 2025

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Jan 24, 2025

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Annotate nullability on SendingRemoteHttpRequestEventArgs

Motivation and Context

Contributes to #14640

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement, Bug fix


Description

  • Annotated nullability for SendingRemoteHttpRequestEventArgs class.

  • Replaced mutable fields with read-only properties for immutability.

  • Added null checks and exceptions for constructor and method parameters.

  • Improved code readability and safety with #nullable enable.


Changes walkthrough 📝

Relevant files
Enhancement
SendingRemoteHttpRequestEventArgs.cs
Annotated nullability and improved immutability.                 

dotnet/src/webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs

  • Enabled nullable reference types with #nullable enable.
  • Annotated nullability for constructor and method parameters.
  • Replaced mutable fields with read-only properties.
  • Added exception handling for null or invalid arguments.
  • +13/-23 

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Sorry, something went wrong.

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    dargmuesli Jonas Thelemann
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Null Validation

    While null checks were added for constructor parameters, the AddHeader method still allows empty string for headerValue parameter which could lead to invalid headers being added

    public void AddHeader(string headerName, string headerValue)
    {
        if (string.IsNullOrEmpty(headerName))
        {

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Prevent duplicate HTTP headers

    The AddHeader method should check if the header already exists before adding it, to
    prevent duplicate headers which could cause issues. Consider adding a check or using
    a different collection method.

    dotnet/src/webdriver/Remote/SendingRemoteHttpRequestEventArgs.cs [81-84]

     public void AddHeader(string headerName, string headerValue)
     {
         if (string.IsNullOrEmpty(headerName))
    -    {
    +        throw new ArgumentException("Header name cannot be null or empty", nameof(headerName));
    +    if (headerValue == null)
    +        throw new ArgumentNullException(nameof(headerValue));
    +    if (this.headers.ContainsKey(headerName))
    +        this.headers[headerName] = headerValue;
    +    else
    +        this.headers.Add(headerName, headerValue);
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a potential bug by handling duplicate headers properly, which is crucial for HTTP request functionality. The improved code also adds proper exception handling and clear error messages, making the code more robust and maintainable.

    8

    Sorry, something went wrong.

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    dargmuesli Jonas Thelemann
    @RenderMichael RenderMichael merged commit 1475d55 into SeleniumHQ:trunk Jan 24, 2025
    10 checks passed
    @RenderMichael RenderMichael deleted the http-event-args branch January 24, 2025 20:46
    sandeepsuryaprasad pushed a commit to sandeepsuryaprasad/selenium that referenced this pull request Mar 23, 2025

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    dargmuesli Jonas Thelemann
    …eleniumHQ#15148)
    
    * [dotnet] Annotate nullability on `SendingRemoteHttpRequestEventArgs`
    
    * Do not consume our public-facing HTTP request event args body
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    2 participants