Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cypress/integration/viewer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Open test.md in viewer', function() {

// Upload test files
cy.uploadFile('test.md', 'text/markdown')
cy.uploadFile('empty.md', 'text/markdown')
})

beforeEach(function() {
Expand Down Expand Up @@ -68,6 +69,30 @@ describe('Open test.md in viewer', function() {
cy.screenshot()
})

it('Open an empty file', function() {
cy.openFile('empty.md')

cy.log('Inspect viewer')
const viewer = cy.get('#viewer')
viewer.should('be.visible')
.and('have.class', 'modal-mask')
.and('not.have.class', 'icon-loading')
viewer.get('.modal-title').should('contain', 'empty.md')
viewer.get('.modal-header button.action-item__menutoggle')
.should('be.visible')

cy.log('Inspect editor')
const editor = viewer.get('#editor .ProseMirror')
editor.should('contain', '')

cy.log('Inspect menubar')
const menubar = editor.get('.menubar .menubar-icons')
menubar.get('.icon-undo').should('be.visible')
menubar.get('.icon-bold').should('be.visible')

cy.screenshot()
})

it('Closes the editor', function() {
cy.openFile('test.md')
cy.get('#viewer .modal-header button.header-close').click()
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function create($fileId = null, $filePath = null, $token = null, $guestNa
$content = $baseFile->getContent();

$content = $this->encodingService->encodeToUtf8($content);
if (!$content) {
if ($content === null) {
$this->logger->log(ILogger::WARN, 'Failed to encode file to UTF8. File ID: ' . $file->getId());
}
} catch (NotFoundException $e) {
Expand Down
3 changes: 2 additions & 1 deletion lib/Service/EncodingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function encodeToUtf8(string $string): ?string {
return null;
}

return mb_convert_encoding($string, 'UTF-8', $encoding);
$encoded = mb_convert_encoding($string, 'UTF-8', $encoding);
return is_string($encoded) ? $encoded : null;
}

public function detectEncoding(string $string): ?string {
Expand Down
2 changes: 1 addition & 1 deletion lib/TextFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getMTime() {

public function getContent() {
$content = $this->encodingService->encodeToUtf8($this->file->getContent());
if (!$content) {
if ($content === null) {
throw new NotFoundException('File not compatible with text because it could not be encoded to UTF-8.');
}

Expand Down