return null;
}
- return 'data:image/' . pathinfo($uri, PATHINFO_EXTENSION) . ';base64,' . base64_encode($imageData);
+ $extension = pathinfo($uri, PATHINFO_EXTENSION);
+ if ($extension === 'svg') {
+ $extension = 'svg+xml';
+ }
+
+ return 'data:image/' . $extension . ';base64,' . base64_encode($imageData);
}
/**
use BookStack\Entities\Chapter;
use BookStack\Entities\Page;
+use BookStack\Uploads\HttpFetcher;
class ExportTest extends TestCase
{
$resp->assertDontSee($page->updated_at->diffForHumans());
}
+ public function test_page_export_sets_right_data_type_for_svg_embeds()
+ {
+ $page = Page::first();
+ $page->html = '<img src="http://example.com/image.svg">';
+ $page->save();
+
+ $this->asEditor();
+ $this->mockHttpFetch('<svg></svg>');
+ $resp = $this->get($page->getUrl('/export/html'));
+ $resp->assertStatus(200);
+ $resp->assertSee('<img src="data:image/svg+xml;base64');
+ }
+
}
\ No newline at end of file
use BookStack\Auth\Permissions\PermissionService;
use BookStack\Entities\Repos\PageRepo;
use BookStack\Settings\SettingService;
+use BookStack\Uploads\HttpFetcher;
trait SharedTestHelpers
{
return $permissionRepo->saveNewRole($roleData);
}
+ /**
+ * Mock the HttpFetcher service and return the given data on fetch.
+ * @param $returnData
+ * @param int $times
+ */
+ protected function mockHttpFetch($returnData, int $times = 1)
+ {
+ $mockHttp = \Mockery::mock(HttpFetcher::class);
+ $this->app[HttpFetcher::class] = $mockHttp;
+ $mockHttp->shouldReceive('fetch')
+ ->times($times)
+ ->andReturn($returnData);
+ }
+
}
\ No newline at end of file