File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -442,7 +442,12 @@ public function imageUriToBase64(string $uri)
442442 return null ;
443443 }
444444
445- return 'data:image/ ' . pathinfo ($ uri , PATHINFO_EXTENSION ) . ';base64, ' . base64_encode ($ imageData );
445+ $ extension = pathinfo ($ uri , PATHINFO_EXTENSION );
446+ if ($ extension === 'svg ' ) {
447+ $ extension = 'svg+xml ' ;
448+ }
449+
450+ return 'data:image/ ' . $ extension . ';base64, ' . base64_encode ($ imageData );
446451 }
447452
448453 /**
Original file line number Diff line number Diff line change 33
44use BookStack \Entities \Chapter ;
55use BookStack \Entities \Page ;
6+ use BookStack \Uploads \HttpFetcher ;
67
78class ExportTest extends TestCase
89{
@@ -148,4 +149,17 @@ public function test_page_html_export_use_absolute_dates()
148149 $ resp ->assertDontSee ($ page ->updated_at ->diffForHumans ());
149150 }
150151
152+ public function test_page_export_sets_right_data_type_for_svg_embeds ()
153+ {
154+ $ page = Page::first ();
155+ $ page ->html = '<img src="http://example.com/image.svg"> ' ;
156+ $ page ->save ();
157+
158+ $ this ->asEditor ();
159+ $ this ->mockHttpFetch ('<svg></svg> ' );
160+ $ resp = $ this ->get ($ page ->getUrl ('/export/html ' ));
161+ $ resp ->assertStatus (200 );
162+ $ resp ->assertSee ('<img src="data:image/svg+xml;base64 ' );
163+ }
164+
151165}
Original file line number Diff line number Diff line change 1111use BookStack \Auth \Permissions \PermissionService ;
1212use BookStack \Entities \Repos \PageRepo ;
1313use BookStack \Settings \SettingService ;
14+ use BookStack \Uploads \HttpFetcher ;
1415
1516trait SharedTestHelpers
1617{
@@ -189,4 +190,18 @@ protected function createNewRole($permissions = [])
189190 return $ permissionRepo ->saveNewRole ($ roleData );
190191 }
191192
193+ /**
194+ * Mock the HttpFetcher service and return the given data on fetch.
195+ * @param $returnData
196+ * @param int $times
197+ */
198+ protected function mockHttpFetch ($ returnData , int $ times = 1 )
199+ {
200+ $ mockHttp = \Mockery::mock (HttpFetcher::class);
201+ $ this ->app [HttpFetcher::class] = $ mockHttp ;
202+ $ mockHttp ->shouldReceive ('fetch ' )
203+ ->times ($ times )
204+ ->andReturn ($ returnData );
205+ }
206+
192207}
You can’t perform that action at this time.
0 commit comments