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] Add nullability to IniFileReader #14929

Merged
merged 4 commits into from
Dec 26, 2024

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Dec 21, 2024

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

Adds nullability annotations and tiny performance improvements to IniFileReader.

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


Description

  • Added nullability annotations to improve type safety and developer experience
  • Enhanced exception documentation with detailed XML comments for better API clarity
  • Improved performance by:
    • Using TryGetValue instead of ContainsKey + dictionary access
    • Making class sealed and fields readonly
    • Simplifying SectionNames property implementation
  • Added input validation for null or empty strings in constructor and methods

Changes walkthrough 📝

Relevant files
Enhancement
IniFileReader.cs
Enhance IniFileReader with nullability and performance improvements

dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs

  • Added nullability annotations and XML documentation for exceptions
  • Optimized performance by using TryGetValue instead of ContainsKey
  • Made class sealed and fields readonly for better optimization
  • Simplified SectionNames property implementation
  • +21/-16 

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    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

    Validation Bug

    The error message for valueName null check incorrectly references sectionName parameter in the XML documentation

            /// <para>If <paramref name="sectionName"/> is <see langword="null"/> or <see cref="string.Empty"/>.</para>
            /// <para>-or-</para>
            /// <para>If <paramref name="sectionName"/> is <see langword="null"/> or <see cref="string.Empty"/>.</para>
    Case Sensitivity

    The code uses ToUpperInvariant() for value names but appears to use case-sensitive comparison for section names, which could lead to inconsistent behavior

                string lowerCaseValueName = valueName.ToUpperInvariant();
    
                if (!this.iniFileStore.TryGetValue(lowerCaseSectionName, out Dictionary<string, string>? section))

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add missing variable declaration to prevent runtime error

    The variable lowerCaseSectionName is used but not defined. Add the missing variable
    declaration to convert sectionName to uppercase for case-insensitive comparison.

    dotnet/src/webdriver/Firefox/Internal/IniFileReader.cs [127]

    +string lowerCaseSectionName = sectionName.ToUpperInvariant();
     if (!this.iniFileStore.TryGetValue(lowerCaseSectionName, out Dictionary<string, string>? section))
    • Apply this suggestion
    Suggestion importance[1-10]: 10

    Why: This suggestion identifies a critical bug where an undefined variable would cause a runtime error. The fix is essential for the code to function properly.

    10

    @nvborisenko nvborisenko merged commit eaf4fa7 into SeleniumHQ:trunk Dec 26, 2024
    10 checks passed
    @nvborisenko
    Copy link
    Member

    Thanks @RenderMichael for your contribution!

    @RenderMichael RenderMichael deleted the ini-file-reader branch December 26, 2024 21:01
    sandeepsuryaprasad pushed a commit to sandeepsuryaprasad/selenium that referenced this pull request Dec 27, 2024
    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.

    2 participants
    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy