From: Bertrand Dunogier Date: Sat, 21 Jan 2017 23:42:05 +0000 (+0100) Subject: Changed parsing of login_extra_fields in guzzle auth X-Git-Tag: 2.3.0~31^2~102^2~1 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=662db41baee404be3427b2b11b2d1fbf0aefcc8f;p=github%2Fwallabag%2Fwallabag.git Changed parsing of login_extra_fields in guzzle auth --- diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php index 6d4129e8..1c866f17 100644 --- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php @@ -54,7 +54,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder 'loginUri' => $config->login_uri ?: null, 'usernameField' => $config->login_username_field ?: null, 'passwordField' => $config->login_password_field ?: null, - 'extraFields' => is_array($config->login_extra_fields) ? $config->login_extra_fields : [], + 'extraFields' => $this->processExtraFields($config->login_extra_fields), 'notLoggedInXpath' => $config->not_logged_in_xpath ?: null, ]; @@ -65,4 +65,30 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder return new SiteConfig($parameters); } + + /** + * Processes login_extra_fields config, transforming an '=' separated array of strings + * into a key/value array. + * + * @param array|mixed $extraFieldsStrings + * + * @return array + */ + protected function processExtraFields($extraFieldsStrings) + { + if (!is_array($extraFieldsStrings)) { + return []; + } + + $extraFields = []; + foreach ($extraFieldsStrings as $extraField) { + if (strpos($extraField, '=') === false) { + continue; + } + list($fieldName, $fieldValue) = explode('=', $extraField, 2); + $extraFields[$fieldName] = $fieldValue; + } + + return $extraFields; + } } diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index aee67259..8341b11f 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -24,7 +24,7 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase $grabySiteConfig->login_uri = 'http://example.com/login'; $grabySiteConfig->login_username_field = 'login'; $grabySiteConfig->login_password_field = 'password'; - $grabySiteConfig->login_extra_fields = ['field' => 'value']; + $grabySiteConfig->login_extra_fields = ['field=value']; $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; $grabyConfigBuilderMock