fix: filter() uses values instead of keys, strips extension capabilities #147
+1
−1
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