diff options
Diffstat (limited to 'browser/components/messagepreview/messagepreview.js')
-rw-r--r-- | browser/components/messagepreview/messagepreview.js | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/browser/components/messagepreview/messagepreview.js b/browser/components/messagepreview/messagepreview.js index 48e5fb1ff5..bec0a2d8eb 100644 --- a/browser/components/messagepreview/messagepreview.js +++ b/browser/components/messagepreview/messagepreview.js @@ -6,13 +6,25 @@ "use strict"; +// decode a 16-bit string in which only one byte of each +// 16-bit unit is occupied, to UTF-8. This is necessary to +// comply with `btoa` API constraints. +function fromBinary(encoded) { + const binary = atob(decodeURIComponent(encoded)); + const bytes = new Uint8Array(binary.length); + for (let i = 0; i < bytes.length; i++) { + bytes[i] = binary.charCodeAt(i); + } + return String.fromCharCode(...new Uint16Array(bytes.buffer)); +} + function decodeMessageFromUrl() { const url = new URL(document.location.href); if (url.searchParams.has("json")) { const encodedMessage = url.searchParams.get("json"); - return atob(encodedMessage); + return fromBinary(encodedMessage); } return null; } |