fix: filter() uses values instead of keys, strips extension capabilities#147
Open
daifma wants to merge 1 commit intoinstaclick:masterfrom
Open
fix: filter() uses values instead of keys, strips extension capabilities#147daifma wants to merge 1 commit intoinstaclick:masterfrom
daifma wants to merge 1 commit intoinstaclick:masterfrom
Conversation
The filter() method had three bugs:
1. array_filter callback received values instead of keys, causing
TypeError when capability values are arrays (e.g. goog:chromeOptions)
2. Extension capabilities (keys containing ':') were stripped, but
W3C spec requires them to be allowed through
3. array_values() destroyed the key-value mapping, turning
{"browserName": "chrome"} into ["chrome"]
Fix by using ARRAY_FILTER_USE_KEY, allowing extension capabilities
per W3C spec, and removing array_values() wrapper.
References:
- https://www.w3.org/TR/webdriver2/#dfn-extension-capability
- https://www.php.net/array_filter
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The
filter()method inWebDriver.phphas three bugs:Bug 1: Callback receives values instead of keys
The current code:
array_filterpasses values to the callback by default. When a capability value is an array(e.g.
goog:chromeOptions→['args' => ['--no-sandbox']]), PHP tries to use the array asan array key in
self::$w3cCapabilities[$capability], causing a TypeError crash.Bug 2: Extension capabilities are stripped
Even if Bug 1 were fixed, the filter only allows keys present in
$w3cCapabilities. This stripsall extension capabilities like
goog:chromeOptions,moz:firefoxOptions,ms:edgeOptions, etc. Per the W3C spec, extensioncapabilities are identified by containing a
:in the key name and MUST be allowed through.Bug 3: array_values destroys key-value pairs
The original code wraps the result in
array_values(), which reindexes the array numerically.This destroys the capability name → value mapping, turning
{"browserName": "chrome"}into["chrome"].Fix
Changes:
ARRAY_FILTER_USE_KEYso the callback receives keys not values:) per W3C specarray_values()to preserve the key-value mappingHow to reproduce
goog:chromeOptions:$webDriver->session('chrome', $capabilities)array(['args' => ...])is used as array keyReferences