Skip to content

Commit c4473de

Browse files
committed
fix(ldapfield): non latin char escaping
Signed-off-by: Thierry Bugier <[email protected]>
1 parent d90c3f9 commit c4473de

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

inc/field/ldapselectfield.class.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@ public function prepareQuestionInputForSave($input) {
282282
'ldap_auth' => $input['ldap_auth'],
283283
'ldap_filter' => $input['ldap_filter'],
284284
'ldap_attribute' => strtolower($input['ldap_attribute']),
285-
]);
285+
], JSON_UNESCAPED_UNICODE);
286+
unset($input['ldap_auth']);
287+
unset($input['ldap_filter']);
288+
unset($input['ldap_attribute']);
286289

287290
return $input;
288291
}

tests/3-unit/GlpiPlugin/Formcreator/Field/LdapSelectField.php

+47-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
*/
3131

3232
namespace GlpiPlugin\Formcreator\Field\tests\units;
33-
use GlpiPlugin\Formcreator\Tests\CommonTestCase;
3433

34+
use AuthLDAP;
35+
use GlpiPlugin\Formcreator\Tests\CommonTestCase;
3536
class LdapSelectField extends CommonTestCase {
3637

3738
public function testGetName() {
@@ -140,4 +141,49 @@ public function testGetValueForDesign($value, $expected) {
140141
$output = $instance->getValueForDesign();
141142
$this->string($output)->isEqualTo($expected);
142143
}
144+
145+
146+
public function providerPrepareQuestionInputForSave() {
147+
$authLdap = new AuthLDAP();
148+
$authLdap->add([]);
149+
150+
return [
151+
[
152+
'input' => [
153+
'ldap_auth' => $authLdap->getID(),
154+
'ldap_filter' => 'по', // Some cyrillic sample
155+
'ldap_attribute' => '',
156+
],
157+
'expected' => [
158+
'values' => json_encode([
159+
'ldap_auth' => $authLdap->getID(),
160+
'ldap_filter' => 'по',
161+
'ldap_attribute' => '',
162+
], JSON_UNESCAPED_UNICODE),
163+
]
164+
],
165+
];
166+
}
167+
168+
/**
169+
* @dataProvider providerPrepareQuestionInputForSave
170+
*
171+
* @param array $input
172+
* @param array $expected
173+
* @return void
174+
*/
175+
public function testPrepareQuestionInputForSave(array $input, array $expected) {
176+
// Make the form private
177+
$question = $this->getQuestion([
178+
'ldap_auth' => $input['ldap_auth'],
179+
'fieldtype' => 'ldapselect',
180+
'ldap_filter' => '',
181+
'ldap_attribute' => '',
182+
]);
183+
184+
$instance = $this->newTestedInstance($question);
185+
186+
$output = $instance->prepareQuestionInputForSave($input);
187+
$this->array($output)->isEqualTo($expected);
188+
}
143189
}

0 commit comments

Comments
 (0)