Skip to content

Commit

Permalink
fix(ldapfield): non latin char escaping
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Nov 29, 2021
1 parent d90c3f9 commit c4473de
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
5 changes: 4 additions & 1 deletion inc/field/ldapselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
48 changes: 47 additions & 1 deletion tests/3-unit/GlpiPlugin/Formcreator/Field/LdapSelectField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit c4473de

Please sign in to comment.