You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix bug where DeleteCookieNamed(null) deletes all cookies by adding null check
Implement proper handling of null cookie names by throwing ArgumentNullException
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review
Error Handling GetCookieNamed method may throw NoSuchCookieException but the interface documentation still mentions returning null for non-existent cookies
Exception Handling The try-catch block in GetAllCookies method has no specific exception type, which could mask important errors
var rawCookie = driver.InternalExecute(DriverCommand.GetCookie, new() { { "name", name } }).Value;
+if (rawCookie == null)+{+ throw new NoSuchCookieException($"No cookie found with name '{name}'");+}
return Cookie.FromDictionary(rawCookie as Dictionary<string, object>);
Apply this suggestion
Suggestion importance[1-10]: 9
Why: This suggestion ensures compliance with the interface contract by throwing NoSuchCookieException when a cookie is not found, as documented in ICookieJar. This is a critical improvement for proper error handling.
9
Add null check for array conversion to prevent runtime exceptions
The GetAllCookies() method should check if cookies is null before attempting to process it, to prevent potential NullReferenceException.
object[] cookies = returned as object[];
+if (cookies == null)+{+ return new ReadOnlyCollection<Cookie>(new List<Cookie>());+}
try
{
Apply this suggestion
Suggestion importance[1-10]: 8
Why: The suggestion addresses a potential null reference exception that could occur during runtime. Adding a null check with proper handling improves the robustness of the code significantly.
Closing this PR because we got more info to move further. Seems Use specification remote endpoint to retrieve a named cookie, instead of fetching all cookies and filter it out on client side is still valid, let's see it in further development.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Description
NoSuchCookieExceptionnullcookie nameMotivation and Context
Fix #14876
Types of changes
Checklist
PR Type
Bug fix, Enhancement
Description
CookieJarclass to remove redundant code and improve cookie management.NoSuchCookieExceptionto handle cases where a cookie is not found.ICookieJarto include exception details.Changes walkthrough 📝
CookieJar.cs
Simplify CookieJar class and improve cookie managementdotnet/src/webdriver/CookieJar.cs
CookieJarclass by removing redundant code.ArgumentNullExceptionfor null parameters.NoSuchCookieException.cs
Introduce NoSuchCookieException classdotnet/src/webdriver/NoSuchCookieException.cs
NoSuchCookieExceptionclass for handling missing cookies.ICookieJar.cs
Add exception handling documentation to ICookieJardotnet/src/webdriver/ICookieJar.cs
ArgumentNullExceptionandNoSuchCookieException.W3CWireProtocolCommandInfoRepository.cs
Correct HTTP method for GetCookie commanddotnet/src/webdriver/Remote/W3CWireProtocolCommandInfoRepository.cs
GetCookiecommand to GET.WebDriver.cs
Handle NoSuchCookieException in WebDriver error responsesdotnet/src/webdriver/WebDriver.cs
NoSuchCookieExceptionin error responses.