Skip to content
Merged

fix #5010

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
2 changes: 1 addition & 1 deletion extension/chrome/elements/attachment_preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ View.run(
this.attachmentPreviewContainer.html(`<img src="${url}" class="attachment-preview-img" alt="${Xss.escape(this.origNameBasedOnFilename)}">`); // xss-escaped
} else if (attachmentType === 'txt') {
// text
this.attachmentPreviewContainer.html(`<div class="attachment-preview-txt">${Xss.escape(result.toString()).replace(/\n/g, '<br>')}</div>`); // xss-escaped
this.attachmentPreviewContainer.html(`<div class="attachment-preview-txt">${Xss.escape(result.toUtfStr()).replace(/\n/g, '<br>')}</div>`); // xss-escaped
} else if (attachmentType === 'pdf') {
// PDF
pdfjsLib.getDocument({ data: result }).promise.then(async (pdf: PDFDocumentProxy) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export class ComposeDraftModule extends ViewModule<ComposeView> {
if (isRichText) {
this.view.sendBtnModule.popover.toggleItemTick($('.action-toggle-richtext-sending-option'), 'richtext', true);
}
this.view.inputModule.inputTextHtmlSetSafely(sanitizedContent.toString());
this.view.inputModule.inputTextHtmlSetSafely(Str.with(sanitizedContent));
this.view.inputModule.squire.focus();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ export class ComposeQuoteModule extends ViewModule<ComposeView> {
const decryptedAndFormatedContent: string[] = [];
const decryptedFiles: File[] = [];
for (const block of readableBlocks) {
const stringContent = block.content.toString();
const stringContent = Str.with(block.content);
if (block.type === 'decryptedHtml') {
const htmlParsed = Xss.htmlSanitizeAndStripAllTags(block ? block.content.toString() : 'No Content', '\n', false);
const htmlParsed = Xss.htmlSanitizeAndStripAllTags(stringContent || 'No Content', '\n', false);
decryptedAndFormatedContent.push(Xss.htmlUnescape(htmlParsed));
} else if (block.type === 'plainHtml') {
decryptedAndFormatedContent.push(Xss.htmlUnescape(Xss.htmlSanitizeAndStripAllTags(stringContent, '\n', false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { Bm, BrowserMsg } from '../../../../js/common/browser/browser-msg.js';
import { FactoryReplyParams, XssSafeFactory } from '../../../../js/common/xss-safe-factory.js';
import { GmailParser, GmailRes } from '../../../../js/common/api/email-provider/gmail/gmail-parser.js';
import { Url, UrlParams } from '../../../../js/common/core/common.js';
import { Str, Url, UrlParams } from '../../../../js/common/core/common.js';

import { ApiErr } from '../../../../js/common/api/shared/api-error.js';
import { BrowserMsgCommonHandlers } from '../../../../js/common/browser/browser-msg-common-handlers.js';
Expand Down Expand Up @@ -128,7 +128,7 @@ export class InboxActiveThreadModule extends ViewModule<InboxView> {
this.view.storage.sendAs && !!this.view.storage.sendAs[from]
);
} else if (this.view.showOriginal) {
r += Xss.escape(block.content.toString()).replace(/\n/g, '<br>');
r += Xss.escape(Str.with(block.content)).replace(/\n/g, '<br>');
} else {
r += XssSafeFactory.renderableMsgBlock(this.view.factory, block, message.id, from, this.view.storage.sendAs && !!this.view.storage.sendAs[from]);
}
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/api/key-server/attester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class Attester extends Api {

private getPubKeysSearchResult = async (r: PubCallRes): Promise<PubkeysSearchResult> => {
const { blocks } = MsgBlockParser.detectBlocks(r.responseText);
const pubkeys = blocks.filter(block => block.type === 'publicKey').map(block => block.content.toString());
const pubkeys = blocks.filter(block => block.type === 'publicKey').map(block => Str.with(block.content));
return { pubkeys };
};

Expand Down
3 changes: 2 additions & 1 deletion extension/js/common/core/buf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ export class Buf extends Uint8Array {
return Buf.fromBase64Str(b64UrlStr.replace(/-/g, '+').replace(/_/g, '/'));
};

/** @deprecated use toUtfStr() instead */
public toString = (mode: 'strict' | 'inform' | 'ignore' = 'inform'): string => {
// mimic Node api
// mimic Buffer.toString()
return this.toUtfStr(mode);
};

Expand Down
4 changes: 2 additions & 2 deletions extension/js/common/core/crypto/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { OpenPGPKey } from './pgp/openpgp-key.js';
import type * as OpenPGP from 'openpgp';
import { SmimeKey } from './smime/smime-key.js';
import { MsgBlock } from '../msg-block.js';
import { EmailParts } from '../common.js';
import { EmailParts, Str } from '../common.js';

/**
* This is a common Key interface for both OpenPGP and X.509 keys.
Expand Down Expand Up @@ -158,7 +158,7 @@ export class KeyUtil {
const pushKeysAndErrs = async (content: string | Buf, isArmored: boolean) => {
try {
if (isArmored) {
allKeys.push(...(await KeyUtil.parseMany(content.toString())));
allKeys.push(...(await KeyUtil.parseMany(Str.with(content))));
} else {
const buf = typeof content === 'string' ? Buf.fromUtfStr(content) : content;
const { keys, err } = await KeyUtil.readBinary(buf);
Expand Down
4 changes: 2 additions & 2 deletions extension/js/common/core/mime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class Mime {
contentNode = new MimeBuilder('multipart/alternative');
for (const [type, content] of Object.entries(body)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
contentNode.appendChild(Mime.newContentNode(MimeBuilder, type, content!.toString())); // already present, that's why part of for loop
contentNode.appendChild(Mime.newContentNode(MimeBuilder, type, Str.with(content!))); // already present, that's why part of for loop
}
}
rootNode.appendChild(contentNode);
Expand Down Expand Up @@ -307,7 +307,7 @@ export class Mime {
const bodyNodes = new MimeBuilder('multipart/alternative');
for (const [type, content] of Object.entries(body)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
bodyNodes.appendChild(Mime.newContentNode(MimeBuilder, type, content!.toString()));
bodyNodes.appendChild(Mime.newContentNode(MimeBuilder, type, Str.with(content!)));
}
const signedContentNode = new MimeBuilder('multipart/mixed');
signedContentNode.appendChild(bodyNodes);
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/core/msg-block-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class MsgBlockParser {
let { blocks, normalized } = MsgBlockParser.detectBlocks(decryptedContent);
for (const block of blocks) {
if (block.type === 'publicKey') {
const armored = block.content.toString();
const armored = Str.with(block.content);
foundPublicKeys.push(armored);
normalized = normalized.replace(armored, '');
}
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/ui/key-import-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class KeyImportUi {
const firstPrv = MsgBlockParser.detectBlocks(utf).blocks.filter(b => b.type === 'privateKey')[0];
if (firstPrv) {
// filter out all content except for the first encountered private key (GPGKeychain compatibility)
prv = await KeyUtil.parse(firstPrv.content.toString());
prv = await KeyUtil.parse(Str.with(firstPrv.content));
}
} else {
try {
Expand Down
14 changes: 7 additions & 7 deletions extension/js/common/xss-safe-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ export class XssSafeFactory {
*/
public static renderableMsgBlock = (factory: XssSafeFactory, block: MsgBlock, msgId: string, senderEmail: string, isOutgoing?: boolean) => {
if (block.type === 'plainText') {
return Xss.escape(block.content.toString()).replace(/\n/g, '<br>') + '<br><br>';
return Xss.escape(Str.with(block.content)).replace(/\n/g, '<br>') + '<br><br>';
} else if (block.type === 'plainHtml') {
return Xss.htmlSanitizeAndStripAllTags(block.content.toString(), '<br>') + '<br><br>';
return Xss.htmlSanitizeAndStripAllTags(Str.with(block.content), '<br>') + '<br><br>';
} else if (block.type === 'encryptedMsg') {
return factory.embeddedMsg(
'encryptedMsg',
block.complete ? PgpArmor.normalize(block.content.toString(), 'encryptedMsg') : '',
block.complete ? PgpArmor.normalize(Str.with(block.content), 'encryptedMsg') : '',
msgId,
isOutgoing,
senderEmail
);
} else if (block.type === 'signedMsg') {
return factory.embeddedMsg('signedMsg', block.content.toString(), msgId, isOutgoing, senderEmail);
return factory.embeddedMsg('signedMsg', Str.with(block.content), msgId, isOutgoing, senderEmail);
} else if (block.type === 'publicKey') {
return factory.embeddedPubkey(PgpArmor.normalize(block.content.toString(), 'publicKey'), isOutgoing);
return factory.embeddedPubkey(PgpArmor.normalize(Str.with(block.content), 'publicKey'), isOutgoing);
} else if (block.type === 'privateKey') {
return factory.embeddedBackup(PgpArmor.normalize(block.content.toString(), 'privateKey'));
return factory.embeddedBackup(PgpArmor.normalize(Str.with(block.content), 'privateKey'));
} else if (block.type === 'certificate') {
return factory.embeddedPubkey(block.content.toString());
return factory.embeddedPubkey(Str.with(block.content));
} else if (['encryptedAttachment', 'plainAttachment'].includes(block.type)) {
return block.attachmentMeta
? factory.embeddedAttachment(new Attachment(block.attachmentMeta), block.type === 'encryptedAttachment')
Expand Down