diff --git a/core/modules/editor/src/Form/EditorImageDialog.php b/core/modules/editor/src/Form/EditorImageDialog.php
index 9c2feb5..a638fdd 100644
--- a/core/modules/editor/src/Form/EditorImageDialog.php
+++ b/core/modules/editor/src/Form/EditorImageDialog.php
@@ -181,7 +181,7 @@ public function buildForm(array $form, FormStateInterface $form_state, FilterFor
 
     // When Drupal core's filter_align is being used, the text editor may
     // offer the ability to change the alignment.
-    if (isset($image_element['data-align']) && $filter_format->filters('filter_align')->status) {
+    if ($filter_format->filters('filter_align')->status) {
       $form['align'] = array(
         '#title' => $this->t('Align'),
         '#type' => 'radios',
@@ -191,7 +191,7 @@ public function buildForm(array $form, FormStateInterface $form_state, FilterFor
           'center' => $this->t('Center'),
           'right' => $this->t('Right'),
         ),
-        '#default_value' => $image_element['data-align'] === '' ? 'none' : $image_element['data-align'],
+        '#default_value' => empty($image_element['data-align']) ? 'none' : $image_element['data-align'],
         '#wrapper_attributes' => array('class' => array('container-inline')),
         '#attributes' => array('class' => array('container-inline')),
         '#parents' => array('attributes', 'data-align'),
@@ -200,11 +200,11 @@ public function buildForm(array $form, FormStateInterface $form_state, FilterFor
 
     // When Drupal core's filter_caption is being used, the text editor may
     // offer the ability to in-place edit the image's caption: show a toggle.
-    if (isset($image_element['hasCaption']) && $filter_format->filters('filter_caption')->status) {
+    if ($filter_format->filters('filter_caption')->status) {
       $form['caption'] = array(
         '#title' => $this->t('Caption'),
         '#type' => 'checkbox',
-        '#default_value' => $image_element['hasCaption'] === 'true',
+        '#default_value' => !empty($image_element['hasCaption']) && $image_element['hasCaption'] === 'true',
         '#parents' => array('attributes', 'hasCaption'),
       );
     }
diff --git a/core/modules/editor/src/Tests/EditorImageDialogTest.php b/core/modules/editor/src/Tests/EditorImageDialogTest.php
new file mode 100644
index 0000000..33e00ca
--- /dev/null
+++ b/core/modules/editor/src/Tests/EditorImageDialogTest.php
@@ -0,0 +1,136 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\editor\Tests\EditorImageDialogTest.
+ */
+
+namespace Drupal\editor\Tests;
+
+use Drupal\Core\Form\FormInterface;
+use Drupal\Core\Form\FormState;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Render\Element\PathElement;
+use Drupal\Core\Url;
+use Drupal\editor\Entity\Editor;
+use Drupal\editor\Form\EditorImageDialog;
+use Drupal\filter\Entity\FilterFormat;
+use Drupal\node\Entity\NodeType;
+use Drupal\simpletest\KernelTestBase;
+use Drupal\system\Tests\Entity\EntityUnitTestBase;
+use Drupal\user\Entity\Role;
+use Drupal\user\Entity\User;
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * Tests EditorImageDialog validation and conversion functionality.
+ *
+ * @group editor
+ */
+class EditorImageDialogTest extends EntityUnitTestBase {
+
+  /**
+   * Filter format for testing.
+   *
+   * @var \Drupal\filter\FilterFormatInterface
+   */
+  protected $format;
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['node', 'file', 'editor', 'editor_test', 'user', 'system'];
+
+  /**
+   * Sets up the test.
+   */
+  protected function setUp() {
+    parent::setUp();
+    $this->installEntitySchema('file');
+    $this->installSchema('system', ['router']);
+    $this->installSchema('node', array('node_access'));
+    $this->installSchema('file', array('file_usage'));
+    $this->installConfig(['node']);
+
+    // Add text formats.
+    $this->format = FilterFormat::create([
+      'format' => 'filtered_html',
+      'name' => 'Filtered HTML',
+      'weight' => 0,
+      'filters' => [
+        'filter_align' => ['status' => TRUE],
+        'filter_caption' => ['status' => TRUE],
+      ],
+    ]);
+    $this->format->save();
+
+    // Set up text editor.
+    $editor = Editor::create([
+      'format' => 'filtered_html',
+      'editor' => 'unicorn',
+      'image_upload' => [
+        'max_size' => 100,
+        'scheme' => 'public',
+        'directory' => '',
+        'status' => TRUE,
+      ],
+    ]);
+    $editor->save();
+
+    // Create a node type for testing.
+    $type = NodeType::create(['type' => 'page', 'name' => 'page']);
+    $type->save();
+    node_add_body_field($type);
+    $this->installEntitySchema('user');
+    \Drupal::service('router.builder')->rebuild();
+  }
+
+  /**
+   * Tests that editor image dialog works as expected.
+   */
+  public function testEditorImageDialog() {
+    $form_state = (new FormState())
+     ->addBuildInfo('args', [$this->format]);
+    $input = [
+      'editor_object' => [
+        'src' => '/sites/default/files/inline-images/somefile.png',
+        'alt' => 'fda',
+        'width' => '',
+        'height' => '',
+        'data-entity-type' => 'file',
+        'data-entity-uuid' => 'some-uuid',
+        'data-align' => 'none',
+        'hasCaption' => 'false',
+      ],
+      'dialogOptions' => [
+        'title' => 'Edit Image',
+        'dialogClass' => 'editor-image-dialog editor-dialog',
+        'autoResize' => 'true',
+      ],
+      '_drupal_ajax' => '1',
+      'ajax_page_state' => [
+        'theme' => 'bartik',
+        'theme_token' => 'some-token',
+        'libraries' => '',
+      ],
+    ];
+    // Fake the request parameters.
+    $request_stack = \Drupal::requestStack();
+    $request = Request::create('/', 'POST', $input);
+    $request_stack->pop();
+    $request_stack->push($request);
+    $form_builder = $this->container->get('form_builder');
+    $form_object = new EditorImageDialog(\Drupal::entityManager()->getStorage('file'));
+    $form_id = $form_builder->getFormId($form_object, $form_state);
+    $form = $form_builder->retrieveForm($form_id, $form_state);
+    $form_builder->prepareForm($form_id, $form, $form_state);
+    $form_builder->processForm($form_id, $form, $form_state);
+
+    // Assert these two values are present and we don't get the 'not-this'
+    // default back.
+    $this->assertEqual(FALSE, $form_state->getValue(['attributes', 'hasCaption'], 'not-this'));
+  }
+
+}
