User description
💥 What does this PR do?
Generates complete url pattern from a single filter parameter
🔧 Implementation Notes
- Rename parameter to filters as a more human parseable name
- Combine patterns and type into one thing. The spec actually supports sending multiple types at the same time, just add it to the array.
- Adds a WEB constant to set http/https filter by default since it currently hangs on data schemas
💡 Additional Considerations
- What do you think about our throwing a warning when the user doesn't put a filter that it may be non-performant?
🔄 Types of changes
- Cleanup (formatting, renaming)
PR Type
Enhancement
Description
-
Simplify BiDi URL pattern API by consolidating parameters
-
Replace separate url_patterns and pattern_type with unified filters parameter
-
Add WEB constant for default HTTP/HTTPS protocol filtering
-
Support multiple input types: String, URI, and Hash patterns
-
Update type signatures and test cases for new API
Diagram Walkthrough
flowchart LR
A["Old API<br/>url_patterns + pattern_type"] -->|Consolidate| B["New API<br/>filters parameter"]
B -->|Supports| C["String patterns"]
B -->|Supports| D["URI objects"]
B -->|Supports| E["Hash patterns"]
B -->|Default| F["WEB constant<br/>HTTP/HTTPS"]
File Walkthrough
| Relevant files |
|---|
| Enhancement |
network.rbSimplify add_intercept method signature
rb/lib/selenium/webdriver/bidi/network.rb
- Simplified
add_intercept method signature by removing url_patterns and
pattern_type parameters - Replaced with single
filters parameter for cleaner API - Updated method call to use new
UrlPattern.format_pattern signature
|
+2/-3 |
url_pattern.rbConsolidate URL pattern generation logic
rb/lib/selenium/webdriver/bidi/network/url_pattern.rb
- Removed separate
format_pattern, to_url_pattern, and
to_url_string_pattern methods - Added
ALLOWED_KEYS constant for pattern hash validation - Added
WEB constant with default HTTP/HTTPS protocol patterns - Implemented unified
format_pattern method supporting String, URI, and Hash inputs - Added private
to_url_pattern method with validation for hash patterns - Returns
WEB patterns by default when filters are empty
|
+28/-28 |
network.rbRemove pattern_type parameter from handlers
rb/lib/selenium/webdriver/common/network.rb
- Removed
pattern_type keyword argument from add_authentication_handler,
add_request_handler, and add_response_handler - Renamed
filter parameter to filters for consistency - Simplified
add_handler private method to remove pattern_type parameter - Updated filter handling to use
Array(filters).flatten for normalization
|
+8/-11 |
|
| Tests |
network_spec.rbUpdate BiDi network tests for new API
rb/spec/integration/selenium/webdriver/bidi/network_spec.rb
- Updated test cases to use new
filters parameter instead of
url_patterns - Removed
pattern_type: :url arguments from test calls - Wrapped pattern strings in arrays to match new API expectations
|
+2/-4 |
network_spec.rbUpdate network handler tests
rb/spec/integration/selenium/webdriver/network_spec.rb
- Removed
pattern_type: :url arguments from add_authentication_handler,
add_request_handler, and add_response_handler test calls - Tests now use simplified API without explicit pattern type
specification
|
+3/-3 |
|
| Documentation |
network.rbsUpdate BiDi network type signatures
rb/sig/lib/selenium/webdriver/bidi/network.rbs
- Updated
add_intercept signature to use filters parameter accepting
Array[String | Hash[Symbol, String]] - Changed
remove_intercept parameter type from String to String? for optional intercept
|
+2/-2 |
url_pattern.rbsUpdate URL pattern type signatures
rb/sig/lib/selenium/webdriver/bidi/network/url_pattern.rbs
- Added
ALLOWED_KEYS and WEB constant type declarations - Updated
format_pattern signature to accept nil | Array[String] |
Array[URI] | Array[Hash[Symbol, String]] - Simplified
to_url_pattern to accept single Hash[Symbol, String] parameter - Removed
to_url_string_pattern method signature
|
+5/-3 |
network.rbsUpdate network handler type signatures
rb/sig/lib/selenium/webdriver/common/network.rbs
- Updated
initialize parameter type from Remote::Bridge to
Remote::BiDiBridge - Removed
pattern_type keyword argument from handler method signatures - Updated filter parameters to accept
String | Hash[Symbol, String] types - Improved type annotations for block parameters and return types
- Updated
add_handler private method signature with new parameter types
|
+5/-5 |
|
PR Compliance Guide 🔍
Below is a summary of compliance checks for this PR:
| Security Compliance |
| 🟢 | No security concerns identified
No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
|
| Ticket Compliance |
| ⚪ | 🎫 No ticket provided
- [ ] Create ticket/issue <!-- /create_ticket --create_ticket=true -->
|
| Codebase Duplication Compliance |
| ⚪ | Codebase context is not defined
Follow the guide to enable codebase context checks.
|
| Custom Compliance |
| 🟢 |
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code self-documenting
Status: Passed
|
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while providing sufficient detail for internal debugging.
Status: Passed
|
Generic: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive information like PII, PHI, or cardholder data.
Status: Passed
|
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent vulnerabilities
Status: Passed
|
| ⚪ |
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis and compliance.
Status: No audit logs: New handler registration and interception code performs critical network intercept actions without introducing any logging of who/what/when, making auditability unclear.
Referred Code
def add_handler(event_type, phase, intercept_type, filters)
intercept = network.add_intercept(phases: [phase], filters: filters)
callback_id = network.on(event_type) do |event|
request = event['request']
intercepted_item = intercept_type.new(network, request)
yield(intercepted_item)
|
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful degradation
Status: Input validation: While filters are validated and TypeError/ArgumentError are raised, the code adding intercepts does not handle these exceptions or empty/default cases explicitly, leaving edge-case handling to callers.
Referred Code
def format_pattern(filters)
patterns = Array(filters).flatten.compact
return WEB.dup if patterns.empty?
patterns.each_with_object([]) do |pattern, array|
case pattern
when String, ::URI::Generic
array << { type: 'string', pattern: pattern.to_s }
when Hash
url_pattern = to_url_pattern(pattern)
if url_pattern.key?(:protocol)
array << url_pattern
else
array << url_pattern.merge(protocol: 'http')
array << url_pattern.merge(protocol: 'https')
end
else
raise TypeError, "pattern must be a String, URI or a Hash of keys: #{ALLOWED_KEYS.join(", ")}"
end
|
|
|
Compliance status legend
🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| General |
Handle empty protocol values in hash patterns
Modify the logic for hash patterns to treat an explicitly empty or nil :protocol value the same as a missing key, defaulting to both http and https protocols.
rb/lib/selenium/webdriver/bidi/network/url_pattern.rb [39-46]
when Hash
url_pattern = to_url_pattern(pattern)
- if url_pattern.key?(:protocol)
+ if url_pattern.key?(:protocol) && !url_pattern[:protocol].to_s.empty?
array << url_pattern
else
array << url_pattern.merge(protocol: 'http')
array << url_pattern.merge(protocol: 'https')
end
- [ ] Apply / Chat <!-- /improve --apply_suggestion=0 -->
Suggestion importance[1-10]: 7
__
Why: The suggestion improves the robustness of hash pattern handling by correctly defaulting to http and https when an empty or nil protocol is explicitly provided, which aligns with the behavior for a missing protocol key.
| Medium
|
| High-level |
Consider making default protocol behavior explicit
The format_pattern method implicitly adds 'http' and 'https' protocols to hash-based filters that lack a protocol. It is suggested to either require the protocol to be explicitly provided to avoid ambiguity, or to clearly document this default behavior.
Examples:
rb/lib/selenium/webdriver/bidi/network/url_pattern.rb [41-46]
if url_pattern.key?(:protocol)
array << url_pattern
else
array << url_pattern.merge(protocol: 'http')
array << url_pattern.merge(protocol: 'https')
end
Solution Walkthrough:
Before:
# rb/lib/selenium/webdriver/bidi/network/url_pattern.rb
def format_pattern(filters)
# ...
patterns.each_with_object([]) do |pattern, array|
case pattern
# ...
when Hash
url_pattern = to_url_pattern(pattern)
if url_pattern.key?(:protocol)
array << url_pattern
else
array << url_pattern.merge(protocol: 'http')
array << url_pattern.merge(protocol: 'https')
end
end
end
end
After:
# rb/lib/selenium/webdriver/bidi/network/url_pattern.rb
def format_pattern(filters)
# ...
patterns.each_with_object([]) do |pattern, array|
case pattern
# ...
when Hash
url_pattern = to_url_pattern(pattern)
unless url_pattern.key?(:protocol)
raise ArgumentError, 'Protocol must be explicit in hash filters.'
end
array << url_pattern
end
end
end
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies an implicit, potentially surprising behavior in the new format_pattern method, which is a valid API design concern that could affect usability.
| Low
|
| Possible issue |
Distinguish between no filters and empty filters
Modify the format_pattern method to distinguish between a nil filters argument, which should use the default WEB patterns, and an empty filters array, which should result in an empty pattern list.
rb/lib/selenium/webdriver/bidi/network/url_pattern.rb [32-33]
+return WEB.dup if filters.nil?
+
patterns = Array(filters).flatten.compact
-return WEB.dup if patterns.empty?
+return [] if patterns.empty?
- [ ] Apply / Chat <!-- /improve --apply_suggestion=2 -->
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies that the current implementation treats a nil filters argument the same as an empty array [], which can be unintuitive. The proposed change makes the API behavior more predictable and robust by distinguishing these cases.
| Low
|
- [ ] More <!-- /improve --more_suggestions=true -->
| |