Skip to content

Commit ad74952

Browse files
committed
fix thumbnails with chinese titles, closes #4478
1 parent 10f3df3 commit ad74952

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

package-lock.json

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/app/services/content_renderer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ async function renderCode(note, $renderedContent) {
117117
}
118118

119119
function renderImage(entity, $renderedContent, options = {}) {
120-
const sanitizedTitle = entity.title.replace(/[^a-z0-9-.]/gi, "");
120+
const encodedTitle = encodeURIComponent(entity.title);
121121

122122
let url;
123123

124124
if (entity instanceof FNote) {
125-
url = `api/images/${entity.noteId}/${sanitizedTitle}?${Math.random()}`;
125+
url = `api/images/${entity.noteId}/${encodedTitle}?${Math.random()}`;
126126
} else if (entity instanceof FAttachment) {
127-
url = `api/attachments/${entity.attachmentId}/image/${sanitizedTitle}?${entity.utcDateModified}">`;
127+
url = `api/attachments/${entity.attachmentId}/image/${encodedTitle}?${entity.utcDateModified}">`;
128128
}
129129

130130
$renderedContent // styles needed for the zoom to work well

src/public/app/widgets/dialogs/revisions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,16 @@ export default class RevisionsDialog extends BasicWidget {
274274

275275
this.$content.html($table);
276276
} else if (revisionItem.type === 'canvas') {
277-
const sanitizedTitle = revisionItem.title.replace(/[^a-z0-9-.]/gi, "");
277+
const encodedTitle = encodeURIComponent(revisionItem.title);
278278

279279
this.$content.html($("<img>")
280-
.attr("src", `api/revisions/${revisionItem.revisionId}/image/${sanitizedTitle}?${Math.random()}`)
280+
.attr("src", `api/revisions/${revisionItem.revisionId}/image/${encodedTitle}?${Math.random()}`)
281281
.css("max-width", "100%"));
282282
} else if (revisionItem.type === 'mermaid') {
283-
const sanitizedTitle = revisionItem.title.replace(/[^a-z0-9-.]/gi, "");
283+
const encodedTitle = encodeURIComponent(revisionItem.title);
284284

285285
this.$content.html($("<img>")
286-
.attr("src", `api/revisions/${revisionItem.revisionId}/image/${sanitizedTitle}?${Math.random()}`)
286+
.attr("src", `api/revisions/${revisionItem.revisionId}/image/${encodedTitle}?${Math.random()}`)
287287
.css("max-width", "100%"));
288288

289289
this.$content.append($("<pre>").text(fullRevision.content));

src/public/app/widgets/type_widgets/editable_text.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
365365
const note = await froca.getNote(noteId);
366366

367367
this.watchdog.editor.model.change( writer => {
368-
const sanitizedTitle = note.title.replace(/[^a-z0-9-.]/gi, "");
369-
const src = `api/images/${note.noteId}/${sanitizedTitle}`;
368+
const encodedTitle = encodeURIComponent(note.title);
369+
const src = `api/images/${note.noteId}/${encodedTitle}`;
370370

371371
const imageElement = writer.createElement( 'image', { 'src': src } );
372372

src/routes/api/clipper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ function processContent(images, note, content) {
153153
const buffer = Buffer.from(dataUrl.split(",")[1], 'base64');
154154

155155
const attachment = imageService.saveImageToAttachment(note.noteId, buffer, filename, true);
156-
const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "");
156+
157+
// We might want to replace with escape-html. For non-latin-based languages, this doesn't work well.
158+
const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "") || "attachment";
157159
const url = `api/attachments/${attachment.attachmentId}/image/${sanitizedTitle}`;
158160

159161
log.info(`Replacing '${imageId}' with '${url}' in note '${note.noteId}'`);

src/services/import/enex.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ function importEnex(taskContext, file, parentNote) {
303303

304304
const attachment = imageService.saveImageToAttachment(noteEntity.noteId, resource.content, originalName, taskContext.data.shrinkImages);
305305

306-
const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "");
306+
// We might want to replace with escape-html. For non-latin-based languages, this doesn't work well.
307+
const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "") || "attachment";
307308
const url = `api/attachments/${attachment.attachmentId}/image/${sanitizedTitle}`;
308309
const imageLink = `<img src="${url}">`;
309310

src/services/notes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,8 @@ function downloadImages(noteId, content) {
529529
const imageService = require('../services/image');
530530
const attachment = imageService.saveImageToAttachment(noteId, imageBuffer, "inline image", true, true);
531531

532-
const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "");
532+
// We might want to replace with escape-html. For non-latin-based languages, this doesn't work well.
533+
const sanitizedTitle = attachment.title.replace(/[^a-z0-9-.]/gi, "") || "attachment";
533534

534535
content = `${content.substr(0, imageMatch.index)}<img src="api/attachments/${attachment.attachmentId}/image/${sanitizedTitle}"${content.substr(imageMatch.index + imageMatch[0].length)}`;
535536
}

0 commit comments

Comments
 (0)