]> BookStack Code Mirror - bookstack/commitdiff
Fixed issue where markdown drafts showed as HTML
authorDan Brown <redacted>
Sun, 14 Nov 2021 12:17:22 +0000 (12:17 +0000)
committerDan Brown <redacted>
Sun, 14 Nov 2021 12:17:22 +0000 (12:17 +0000)
Markdown content was not being stored, only the sent
HTML representation, causing the draft to show as HTML upon next edit.
Added test to cover.

Fixes #3054

app/Entities/Repos/PageRepo.php
tests/Entity/PageDraftTest.php

index 98fe4ef5569646e42a7a5e981195d8ed52f128ed..f66f2beb8ce16d9930b904c2e9c5e969d27fc7ae 100644 (file)
@@ -252,9 +252,7 @@ class PageRepo
     {
         // If the page itself is a draft simply update that
         if ($page->draft) {
-            if (isset($input['html'])) {
-                (new PageContent($page))->setNewHTML($input['html']);
-            }
+            $this->updateTemplateStatusAndContentFromInput($page, $input);
             $page->fill($input);
             $page->save();
 
index 9e2ceff51a1e5cf0a0175cced31a2ac1c29b096b..ec6707bc5b8cada845f9f1956499cbcea49e01a3 100644 (file)
@@ -178,4 +178,30 @@ class PageDraftTest extends TestCase
             'html' => $page->html,
         ]);
     }
+
+    public function test_updating_page_draft_with_markdown_retains_markdown_content()
+    {
+        /** @var Book $book */
+        $book = Book::query()->first();
+        $this->asEditor()->get($book->getUrl('/create-page'));
+        /** @var Page $draft */
+        $draft = Page::query()->where('draft', '=', true)->where('book_id', '=', $book->id)->firstOrFail();
+
+        $resp = $this->put('/ajax/page/' . $draft->id . '/save-draft', [
+            'name' => 'My updated draft',
+            'markdown' => "# My markdown page\n\n[A link](https://example.com)",
+            'html' => '<p>checking markdown takes priority over this</p>'
+        ]);
+        $resp->assertOk();
+
+        $this->assertDatabaseHas('pages', [
+            'id' => $draft->id,
+            'draft' => true,
+            'name' => 'My updated draft',
+            'markdown' => "# My markdown page\n\n[A link](https://example.com)",
+        ]);
+
+        $draft->refresh();
+        $this->assertStringContainsString('href="https://example.com"', $draft->html);
+    }
 }