parent
629b7a674e
commit
1e7df28238
|
@ -442,7 +442,12 @@ class ImageService extends UploadService
|
||||||
return null;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
use BookStack\Entities\Chapter;
|
use BookStack\Entities\Chapter;
|
||||||
use BookStack\Entities\Page;
|
use BookStack\Entities\Page;
|
||||||
|
use BookStack\Uploads\HttpFetcher;
|
||||||
|
|
||||||
class ExportTest extends TestCase
|
class ExportTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -148,4 +149,17 @@ class ExportTest extends TestCase
|
||||||
$resp->assertDontSee($page->updated_at->diffForHumans());
|
$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');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ use BookStack\Auth\Role;
|
||||||
use BookStack\Auth\Permissions\PermissionService;
|
use BookStack\Auth\Permissions\PermissionService;
|
||||||
use BookStack\Entities\Repos\PageRepo;
|
use BookStack\Entities\Repos\PageRepo;
|
||||||
use BookStack\Settings\SettingService;
|
use BookStack\Settings\SettingService;
|
||||||
|
use BookStack\Uploads\HttpFetcher;
|
||||||
|
|
||||||
trait SharedTestHelpers
|
trait SharedTestHelpers
|
||||||
{
|
{
|
||||||
|
@ -189,4 +190,18 @@ trait SharedTestHelpers
|
||||||
return $permissionRepo->saveNewRole($roleData);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue