fix(inline-attachments): Handle images with UTF16 names

This commit is contained in:
Ben Gotow 2016-11-15 17:04:43 -08:00
parent 8332ecf95e
commit b758ffe589

View file

@ -1,9 +1,17 @@
import {Actions, Utils} from 'nylas-exports';
function safeEncode(str) {
return btoa(unescape(encodeURIComponent(str)));
}
function safeDecode(str) {
return atob(decodeURIComponent(escape(str)))
}
function _runOnImageNode(node) {
if (node.src && node.dataset.nylasFile) {
node.addEventListener('error', () => {
const file = JSON.parse(atob(node.dataset.nylasFile), Utils.registeredObjectReviver);
const file = JSON.parse(safeDecode(node.dataset.nylasFile), Utils.registeredObjectReviver);
const initialDisplay = node.style.display;
const downloadButton = document.createElement('a');
downloadButton.classList.add('inline-download-prompt')
@ -22,7 +30,7 @@ function _runOnImageNode(node) {
}
export function encodedAttributeForFile(file) {
return btoa(JSON.stringify(file, Utils.registeredObjectReplacer));
return safeEncode(JSON.stringify(file, Utils.registeredObjectReplacer));
}
export function addInlineDownloadPrompts(doc) {