Verified Commit c62e7d1c authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3276213 by nod_, Wim Leers, lauriii, mherchel, longwave: Uncaught...

Issue #3276213 by nod_, Wim Leers, lauriii, mherchel, longwave: Uncaught exception when data-caption contains markup upcasting to a model element

(cherry picked from commit afc43ea0)
parent dbaa5e87
Loading
Loading
Loading
Loading
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+1 −8
Original line number Diff line number Diff line
@@ -478,20 +478,13 @@ function viewImageToModelImage(editor) {
      const viewFragment = editor.data.processor.toView(
        viewItem.getAttribute('data-caption'),
      );
      const modelFragment = writer.createDocumentFragment();

      // Consumable must know about those newly parsed view elements.
      conversionApi.consumable.constructor.createFrom(
        viewFragment,
        conversionApi.consumable,
      );
      conversionApi.convertChildren(viewFragment, modelFragment);

      // Insert caption model nodes into the caption.
      // eslint-disable-next-line no-restricted-syntax
      for (const child of Array.from(modelFragment.getChildren())) {
        writer.append(child, caption);
      }
      conversionApi.convertChildren(viewFragment, caption);

      // Insert the caption element into image, as a last child.
      writer.append(caption, image);
+1 −8
Original line number Diff line number Diff line
@@ -36,20 +36,13 @@ function viewToModelCaption(editor) {
    const viewFragment = editor.data.processor.toView(
      viewItem.getAttribute('data-caption'),
    );
    const modelFragment = writer.createDocumentFragment();

    // Consumable must know about those newly parsed view elements.
    conversionApi.consumable.constructor.createFrom(
      viewFragment,
      conversionApi.consumable,
    );
    conversionApi.convertChildren(viewFragment, modelFragment);

    // Insert caption model nodes into the caption.
    // eslint-disable-next-line no-restricted-syntax
    for (const child of Array.from(modelFragment.getChildren())) {
      writer.append(child, caption);
    }
    conversionApi.convertChildren(viewFragment, caption);

    // Insert the caption element into drupalMedia, as a last child.
    writer.append(caption, drupalMedia);
+5 −5
Original line number Diff line number Diff line
@@ -574,7 +574,7 @@ public function testImageCaption() {

    // The foo attribute is added to be removed later by CKEditor 5 to make sure
    // CKEditor 5 was able to downcast data.
    $img_tag = '<img ' . $this->imageAttributesAsString() . ' alt="drupalimage test image" data-caption="Alpacas &lt;em&gt;are&lt;/em&gt; cute" foo="bar">';
    $img_tag = '<img ' . $this->imageAttributesAsString() . ' alt="drupalimage test image" data-caption="Alpacas &lt;em&gt;are&lt;/em&gt; cute&lt;br&gt;really!" foo="bar">';
    $this->host->body->value = $img_tag;
    $this->host->save();

@@ -583,18 +583,18 @@ public function testImageCaption() {

    $this->assertNotEmpty($assert_session->waitForElement('css', '.ck-editor'));
    $this->assertNotEmpty($figcaption = $assert_session->waitForElement('css', '.image figcaption'));
    $this->assertSame('Alpacas <em>are</em> cute', $figcaption->getHtml());
    $this->assertSame('Alpacas <em>are</em> cute<br>really!', $figcaption->getHtml());
    $page->pressButton('Source');
    $editor_dom = $this->getEditorDataAsDom();
    $data_caption = $editor_dom->getElementsByTagName('img')->item(0)->getAttribute('data-caption');
    $this->assertSame('Alpacas <em>are</em> cute', $data_caption);
    $this->assertSame('Alpacas <em>are</em> cute<br>really!', $data_caption);

    $page->pressButton('Save');

    $src = $this->imageAttributes()['src'];
    $this->assertEquals('<img ' . $this->imageAttributesAsString(TRUE) . ' alt="drupalimage test image" data-caption="Alpacas &lt;em&gt;are&lt;/em&gt; cute">', Node::load(1)->get('body')->value);
    $this->assertEquals('<img ' . $this->imageAttributesAsString(TRUE) . ' alt="drupalimage test image" data-caption="Alpacas &lt;em&gt;are&lt;/em&gt; cute&lt;br&gt;really!">', Node::load(1)->get('body')->value);
    $assert_session->elementExists('xpath', '//figure/img[@src="' . $src . '" and not(@data-caption)]');
    $assert_session->responseContains('<figcaption>Alpacas <em>are</em> cute</figcaption>');
    $assert_session->responseContains('<figcaption>Alpacas <em>are</em> cute<br>really!</figcaption>');
  }

  /**
Loading