From c4473de3d60688a06562befa7667f01d3806baa6 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Fri, 26 Nov 2021 08:51:22 +0100 Subject: [PATCH] fix(ldapfield): non latin char escaping Signed-off-by: Thierry Bugier --- inc/field/ldapselectfield.class.php | 5 +- .../Formcreator/Field/LdapSelectField.php | 48 ++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/inc/field/ldapselectfield.class.php b/inc/field/ldapselectfield.class.php index 2f1f626e9..8ddca0c71 100644 --- a/inc/field/ldapselectfield.class.php +++ b/inc/field/ldapselectfield.class.php @@ -282,7 +282,10 @@ public function prepareQuestionInputForSave($input) { 'ldap_auth' => $input['ldap_auth'], 'ldap_filter' => $input['ldap_filter'], 'ldap_attribute' => strtolower($input['ldap_attribute']), - ]); + ], JSON_UNESCAPED_UNICODE); + unset($input['ldap_auth']); + unset($input['ldap_filter']); + unset($input['ldap_attribute']); return $input; } diff --git a/tests/3-unit/GlpiPlugin/Formcreator/Field/LdapSelectField.php b/tests/3-unit/GlpiPlugin/Formcreator/Field/LdapSelectField.php index 2dcd37de3..5c843cca6 100644 --- a/tests/3-unit/GlpiPlugin/Formcreator/Field/LdapSelectField.php +++ b/tests/3-unit/GlpiPlugin/Formcreator/Field/LdapSelectField.php @@ -30,8 +30,9 @@ */ namespace GlpiPlugin\Formcreator\Field\tests\units; -use GlpiPlugin\Formcreator\Tests\CommonTestCase; +use AuthLDAP; +use GlpiPlugin\Formcreator\Tests\CommonTestCase; class LdapSelectField extends CommonTestCase { public function testGetName() { @@ -140,4 +141,49 @@ public function testGetValueForDesign($value, $expected) { $output = $instance->getValueForDesign(); $this->string($output)->isEqualTo($expected); } + + + public function providerPrepareQuestionInputForSave() { + $authLdap = new AuthLDAP(); + $authLdap->add([]); + + return [ + [ + 'input' => [ + 'ldap_auth' => $authLdap->getID(), + 'ldap_filter' => 'по', // Some cyrillic sample + 'ldap_attribute' => '', + ], + 'expected' => [ + 'values' => json_encode([ + 'ldap_auth' => $authLdap->getID(), + 'ldap_filter' => 'по', + 'ldap_attribute' => '', + ], JSON_UNESCAPED_UNICODE), + ] + ], + ]; + } + + /** + * @dataProvider providerPrepareQuestionInputForSave + * + * @param array $input + * @param array $expected + * @return void + */ + public function testPrepareQuestionInputForSave(array $input, array $expected) { + // Make the form private + $question = $this->getQuestion([ + 'ldap_auth' => $input['ldap_auth'], + 'fieldtype' => 'ldapselect', + 'ldap_filter' => '', + 'ldap_attribute' => '', + ]); + + $instance = $this->newTestedInstance($question); + + $output = $instance->prepareQuestionInputForSave($input); + $this->array($output)->isEqualTo($expected); + } }