fix: filter() uses values instead of keys, strips extension capabilities#147
fix: filter() uses values instead of keys, strips extension capabilities#147daifma wants to merge 2 commits 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
|
@daifma , what the If that is so, then we might risk deleting some capabilities that are enabled by default, but the user wants them disabled. |
|
@aik099 The critical part of the fix is the $capabilities = [
'acceptInsecureCerts' => false, // kept — key is in $w3cCapabilities
'browserName' => 'chrome', // kept — key is in $w3cCapabilities
'goog:chromeOptions' => [...], // kept — key contains ':'
'unknownCap' => 'value', // removed — not W3C, no ':'
];Capabilities set to The old code had the opposite problem: without |
Add WebDriverFilterTest covering 8 test cases: - Non-W3C capabilities are stripped - All W3C standard capabilities pass through - Vendor extension capabilities (with ':') are preserved - Falsy values (false, 0) are NOT stripped (addresses review concern) - Null capabilities handled gracefully - requiredCapabilities (alwaysMatch) also filtered - Legacy capability names remapped to W3C equivalents - Key-value mapping preserved (not reindexed numerically)
a39a3c0 to
9d89e62
Compare
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