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 firefox and chromium options #15206

Merged
merged 2 commits into from
Feb 1, 2025

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Feb 1, 2025

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.

Annotate nullability on firefox and chromium options

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.

Copy link
Contributor

qodo-merge-pro bot commented Feb 1, 2025

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 Handling

The SetEnvironmentVariable method accepts a nullable string parameter but doesn't validate if variableValue is null before using it. While it's handled by setting empty string, this should be documented in the method's XML comments.

public void SetEnvironmentVariable(string variableName, string? variableValue)
{
    if (string.IsNullOrEmpty(variableName))
    {
        throw new ArgumentException("Environment variable name cannot be null or an empty string");
    }

    this.environmentVariables[variableName] = variableValue ?? string.Empty;
}

Copy link
Contributor

qodo-merge-pro bot commented Feb 1, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Score
Possible issue
Validate individual arguments for null/empty

The AddArguments() method with params string[] parameter should validate individual
arguments, not just check if the array is null. Each argument should be validated to
not be null or empty.

dotnet/src/webdriver/Firefox/FirefoxOptions.cs [150-153]

 public void AddArguments(params string[] argumentsToAdd)
 {
+    if (argumentsToAdd == null)
+        throw new ArgumentNullException(nameof(argumentsToAdd));
+        
+    foreach(var arg in argumentsToAdd)
+    {
+        if (string.IsNullOrEmpty(arg))
+            throw new ArgumentException("Arguments cannot be null or empty", nameof(argumentsToAdd));
+    }
     this.AddArguments((IEnumerable<string>)argumentsToAdd);
 }
  • Apply this suggestion
Suggestion importance[1-10]: 8

Why: The suggestion addresses a potential bug where invalid (null/empty) arguments could be silently accepted. Adding validation for individual arguments improves robustness and helps catch errors earlier.

8

@RenderMichael RenderMichael merged commit 01a96d9 into SeleniumHQ:trunk Feb 1, 2025
10 checks passed
@RenderMichael RenderMichael deleted the ff-chromium-options branch February 1, 2025 05:54
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.

1 participant