Issue #2617152 by Chi, alexpott, dawehner: Single import form needs to handle invalid YAML correctly and not with an exception

8.2.x
Alex Pott 2016-05-19 16:15:49 +01:00
parent 2a6e3990ce
commit 6632005171
2 changed files with 18 additions and 2 deletions

View File

@ -2,6 +2,7 @@
namespace Drupal\config\Form;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Drupal\Component\Serialization\Yaml;
use Drupal\config\StorageReplaceDataWrapper;
use Drupal\Core\Config\ConfigImporter;
@ -281,8 +282,13 @@ class ConfigSingleImportForm extends ConfirmFormBase {
return;
}
try {
// Decode the submitted import.
$data = Yaml::decode($form_state->getValue('import'));
}
catch (InvalidDataTypeException $e) {
$form_state->setErrorByName('import', $this->t('The import failed with the following message: %message', ['%message' => $e->getMessage()]));
}
// Validate for config entities.
if ($form_state->getValue('config_type') !== 'system.simple') {

View File

@ -37,6 +37,16 @@ class ConfigSingleImportExportTest extends WebTestBase {
$uuid = \Drupal::service('uuid');
$this->drupalLogin($this->drupalCreateUser(array('import configuration')));
// Attempt an import with invalid YAML.
$edit = [
'config_type' => 'action',
'import' => '{{{',
];
$this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
$this->assertText('The import failed with the following message: Malformed inline YAML string ({{{) at line 1 (near "{{{")');
$import = <<<EOD
label: First
weight: 0