mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-05-04 18:08:46 +03:00
Revision Diffs: Added filtering post-diff render
This commit is contained in:
@@ -12,6 +12,8 @@ use BookStack\Exceptions\NotFoundException;
|
||||
use BookStack\Facades\Activity;
|
||||
use BookStack\Http\Controller;
|
||||
use BookStack\Permissions\Permission;
|
||||
use BookStack\Util\HtmlContentFilter;
|
||||
use BookStack\Util\HtmlContentFilterConfig;
|
||||
use BookStack\Util\SimpleListOptions;
|
||||
use Illuminate\Http\Request;
|
||||
use Ssddanbrown\HtmlDiff\Diff;
|
||||
@@ -101,12 +103,15 @@ class PageRevisionController extends Controller
|
||||
|
||||
$prev = $revision->getPreviousRevision();
|
||||
$prevContent = $prev->html ?? '';
|
||||
$diff = Diff::excecute($prevContent, $revision->html);
|
||||
|
||||
// TODO - Refactor PageContent so we can de-dupe these steps
|
||||
$rawDiff = Diff::excecute($prevContent, $revision->html);
|
||||
$filterConfig = HtmlContentFilterConfig::fromConfigString(config('app.content_filtering'));
|
||||
$filter = new HtmlContentFilter($filterConfig);
|
||||
$diff = $filter->filterString($rawDiff);
|
||||
|
||||
$page->fill($revision->toArray());
|
||||
// TODO - Refactor PageContent so we don't need to juggle this
|
||||
$page->html = $revision->html;
|
||||
$page->html = (new PageContent($page))->render();
|
||||
$page->html = '';
|
||||
$this->setPageTitle(trans('entities.pages_revision_named', ['pageName' => $page->getShortName()]));
|
||||
|
||||
return view('pages.revision', [
|
||||
|
||||
@@ -47,6 +47,20 @@ class PageRevisionTest extends TestCase
|
||||
$revisionView->assertSee('new revision content');
|
||||
}
|
||||
|
||||
public function test_page_revision_preview_filters_html_content()
|
||||
{
|
||||
$this->asEditor();
|
||||
$page = $this->entities->page();
|
||||
$this->createRevisions($page, 1, ['name' => 'updated page', 'html' => '<script>dontwantthishere</script><style>dontwantthishere</style><p>expectthisthough</p>']);
|
||||
$pageRevision = $page->revisions->last();
|
||||
$this->createRevisions($page, 1, ['name' => 'updated page', 'html' => '<p>Updated content</p>']);
|
||||
|
||||
$revisionView = $this->get($page->getUrl() . '/revisions/' . $pageRevision->id);
|
||||
$revisionView->assertStatus(200);
|
||||
$revisionView->assertSee('expectthisthough');
|
||||
$revisionView->assertDontSee('dontwantthishere');
|
||||
}
|
||||
|
||||
public function test_page_revision_restore_updates_content()
|
||||
{
|
||||
$this->asEditor();
|
||||
@@ -215,6 +229,21 @@ class PageRevisionTest extends TestCase
|
||||
$html->assertElementContains('.item-list > .item-list-row:nth-child(2)', 'Changes');
|
||||
}
|
||||
|
||||
public function test_page_changes_view_filters_html_content()
|
||||
{
|
||||
$this->asEditor();
|
||||
$page = $this->entities->page();
|
||||
$html = '<script>dontwantthishere</script><style>dontwantthishere</style><p>expectthisthough</p>';
|
||||
$this->createRevisions($page, 1, ['name' => 'updated page', 'html' => $html]);
|
||||
$this->createRevisions($page, 1, ['name' => 'updated page', 'html' => $html]);
|
||||
|
||||
$pageRevision = $page->revisions->last();
|
||||
$revisionView = $this->get("{$page->getUrl()}/revisions/{$pageRevision->id}/changes");
|
||||
$revisionView->assertStatus(200);
|
||||
$revisionView->assertSee('expectthisthough');
|
||||
$revisionView->assertDontSee('dontwantthishere');
|
||||
}
|
||||
|
||||
public function test_revision_restore_action_only_visible_with_permission()
|
||||
{
|
||||
$page = $this->entities->page();
|
||||
|
||||
Reference in New Issue
Block a user