-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(target): remove abusive encoding in target names
- Loading branch information
Showing
5 changed files
with
97 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,46 @@ | ||
<?php | ||
|
||
function plugin_formcreator_update_dev(Migration $migration) { | ||
global $DB; | ||
|
||
// Change id of search option for status of form_answer | ||
$table = 'glpi_displaypreferences'; | ||
$query = "UPDATE `$table` SET `num`='8' WHERE `itemtype`='PluginFormcreatorForm_Answer' AND `num`='1'"; | ||
$DB->query($query); | ||
} | ||
|
||
// Remove abusive encoding in targets | ||
$table = 'glpi_plugin_formcreator_targets'; | ||
$request = [ | ||
'FROM' => $table, | ||
]; | ||
foreach ($DB->request($request) as $row) { | ||
$id = $row['id']; | ||
$name = Toolbox::addslashes_deep(html_entity_decode($row['name'], ENT_QUOTES|ENT_HTML5)); | ||
$id = $row['id']; | ||
$DB->query("UPDATE `$table` SET `name`='$name' WHERE `id` = '$id'"); | ||
} | ||
|
||
// Remove abusive encding in target tickets | ||
$table = 'glpi_plugin_formcreator_targettickets'; | ||
$request = [ | ||
'FROM' => $table, | ||
]; | ||
foreach ($DB->request($request) as $row) { | ||
$id = $row['id']; | ||
$name = Toolbox::addslashes_deep(html_entity_decode($row['name'], ENT_QUOTES|ENT_HTML5)); | ||
$id = $row['id']; | ||
$DB->query("UPDATE `$table` SET `name`='$name' WHERE `id` = '$id'"); | ||
} | ||
|
||
// Remove abusive encding in target tickets | ||
$table = 'glpi_plugin_formcreator_targetchanges'; | ||
$request = [ | ||
'FROM' => $table, | ||
]; | ||
foreach ($DB->request($request) as $row) { | ||
$id = $row['id']; | ||
$name = Toolbox::addslashes_deep(html_entity_decode($row['name'], ENT_QUOTES|ENT_HTML5)); | ||
$id = $row['id']; | ||
$DB->query("UPDATE `$table` SET `name`='$name' WHERE `id` = '$id'"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
class TargetTest extends SuperAdminTestCase { | ||
|
||
public function addUpdateFormProvider() { | ||
return [ | ||
[ | ||
'input' => [ | ||
'name' => '', | ||
'itemtype' => PluginFormcreatorTargetTicket::class | ||
], | ||
'expected' => false, | ||
], | ||
[ | ||
'input' => [ | ||
'name' => 'should fail', | ||
'itemtype' => '' | ||
], | ||
'expected' => false, | ||
], | ||
[ | ||
'input' => [ | ||
'name' => 'should pass', | ||
'itemtype' => PluginFormcreatorTargetTicket::class | ||
], | ||
'expected' => true, | ||
], | ||
[ | ||
'input' => [ | ||
'name' => 'être ou ne pas être', | ||
'itemtype' => PluginFormcreatorTargetTicket::class | ||
], | ||
'expected' => true, | ||
], | ||
[ | ||
'input' => [ | ||
'name' => 'test d\\\'apostrophe', | ||
'itemtype' => PluginFormcreatorTargetTicket::class | ||
], | ||
'expected' => true, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider addUpdateFormProvider | ||
* @param array $input | ||
* @param boolean $expected | ||
*/ | ||
public function testPrepareInputForAdd($input, $expected) { | ||
$target = new PluginFormcreatorTarget(); | ||
$output = $target->prepareInputForAdd($input); | ||
if ($expected === false) { | ||
$this->assertCount(0, $output); | ||
} else { | ||
$this->assertEquals($input['name'], $output['name']); | ||
$this->assertArrayHasKey('uuid', $output); | ||
} | ||
} | ||
} |