Skip to content

Commit d674533

Browse files
rrrooommmaaaRoman Shevchenko
andauthored
fix (#5010)
* fix * refactorings --------- Co-authored-by: Roman Shevchenko <[email protected]>
1 parent e5fe861 commit d674533

File tree

11 files changed

+22
-21
lines changed

11 files changed

+22
-21
lines changed

extension/chrome/elements/attachment_preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ View.run(
5858
this.attachmentPreviewContainer.html(`<img src="${url}" class="attachment-preview-img" alt="${Xss.escape(this.origNameBasedOnFilename)}">`); // xss-escaped
5959
} else if (attachmentType === 'txt') {
6060
// text
61-
this.attachmentPreviewContainer.html(`<div class="attachment-preview-txt">${Xss.escape(result.toString()).replace(/\n/g, '<br>')}</div>`); // xss-escaped
61+
this.attachmentPreviewContainer.html(`<div class="attachment-preview-txt">${Xss.escape(result.toUtfStr()).replace(/\n/g, '<br>')}</div>`); // xss-escaped
6262
} else if (attachmentType === 'pdf') {
6363
// PDF
6464
pdfjsLib.getDocument({ data: result }).promise.then(async (pdf: PDFDocumentProxy) => {

extension/chrome/elements/compose-modules/compose-draft-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export class ComposeDraftModule extends ViewModule<ComposeView> {
331331
if (isRichText) {
332332
this.view.sendBtnModule.popover.toggleItemTick($('.action-toggle-richtext-sending-option'), 'richtext', true);
333333
}
334-
this.view.inputModule.inputTextHtmlSetSafely(sanitizedContent.toString());
334+
this.view.inputModule.inputTextHtmlSetSafely(Str.with(sanitizedContent));
335335
this.view.inputModule.squire.focus();
336336
};
337337

extension/chrome/elements/compose-modules/compose-quote-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ export class ComposeQuoteModule extends ViewModule<ComposeView> {
117117
const decryptedAndFormatedContent: string[] = [];
118118
const decryptedFiles: File[] = [];
119119
for (const block of readableBlocks) {
120-
const stringContent = block.content.toString();
120+
const stringContent = Str.with(block.content);
121121
if (block.type === 'decryptedHtml') {
122-
const htmlParsed = Xss.htmlSanitizeAndStripAllTags(block ? block.content.toString() : 'No Content', '\n', false);
122+
const htmlParsed = Xss.htmlSanitizeAndStripAllTags(stringContent || 'No Content', '\n', false);
123123
decryptedAndFormatedContent.push(Xss.htmlUnescape(htmlParsed));
124124
} else if (block.type === 'plainHtml') {
125125
decryptedAndFormatedContent.push(Xss.htmlUnescape(Xss.htmlSanitizeAndStripAllTags(stringContent, '\n', false)));

extension/chrome/settings/inbox/inbox-modules/inbox-active-thread-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { Bm, BrowserMsg } from '../../../../js/common/browser/browser-msg.js';
66
import { FactoryReplyParams, XssSafeFactory } from '../../../../js/common/xss-safe-factory.js';
77
import { GmailParser, GmailRes } from '../../../../js/common/api/email-provider/gmail/gmail-parser.js';
8-
import { Url, UrlParams } from '../../../../js/common/core/common.js';
8+
import { Str, Url, UrlParams } from '../../../../js/common/core/common.js';
99

1010
import { ApiErr } from '../../../../js/common/api/shared/api-error.js';
1111
import { BrowserMsgCommonHandlers } from '../../../../js/common/browser/browser-msg-common-handlers.js';
@@ -128,7 +128,7 @@ export class InboxActiveThreadModule extends ViewModule<InboxView> {
128128
this.view.storage.sendAs && !!this.view.storage.sendAs[from]
129129
);
130130
} else if (this.view.showOriginal) {
131-
r += Xss.escape(block.content.toString()).replace(/\n/g, '<br>');
131+
r += Xss.escape(Str.with(block.content)).replace(/\n/g, '<br>');
132132
} else {
133133
r += XssSafeFactory.renderableMsgBlock(this.view.factory, block, message.id, from, this.view.storage.sendAs && !!this.view.storage.sendAs[from]);
134134
}

extension/js/common/api/key-server/attester.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class Attester extends Api {
107107

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

extension/js/common/core/buf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ export class Buf extends Uint8Array {
9797
return Buf.fromBase64Str(b64UrlStr.replace(/-/g, '+').replace(/_/g, '/'));
9898
};
9999

100+
/** @deprecated use toUtfStr() instead */
100101
public toString = (mode: 'strict' | 'inform' | 'ignore' = 'inform'): string => {
101-
// mimic Node api
102+
// mimic Buffer.toString()
102103
return this.toUtfStr(mode);
103104
};
104105

extension/js/common/core/crypto/key.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { OpenPGPKey } from './pgp/openpgp-key.js';
1111
import type * as OpenPGP from 'openpgp';
1212
import { SmimeKey } from './smime/smime-key.js';
1313
import { MsgBlock } from '../msg-block.js';
14-
import { EmailParts } from '../common.js';
14+
import { EmailParts, Str } from '../common.js';
1515

1616
/**
1717
* This is a common Key interface for both OpenPGP and X.509 keys.
@@ -158,7 +158,7 @@ export class KeyUtil {
158158
const pushKeysAndErrs = async (content: string | Buf, isArmored: boolean) => {
159159
try {
160160
if (isArmored) {
161-
allKeys.push(...(await KeyUtil.parseMany(content.toString())));
161+
allKeys.push(...(await KeyUtil.parseMany(Str.with(content))));
162162
} else {
163163
const buf = typeof content === 'string' ? Buf.fromUtfStr(content) : content;
164164
const { keys, err } = await KeyUtil.readBinary(buf);

extension/js/common/core/mime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class Mime {
259259
contentNode = new MimeBuilder('multipart/alternative');
260260
for (const [type, content] of Object.entries(body)) {
261261
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
262-
contentNode.appendChild(Mime.newContentNode(MimeBuilder, type, content!.toString())); // already present, that's why part of for loop
262+
contentNode.appendChild(Mime.newContentNode(MimeBuilder, type, Str.with(content!))); // already present, that's why part of for loop
263263
}
264264
}
265265
rootNode.appendChild(contentNode);
@@ -307,7 +307,7 @@ export class Mime {
307307
const bodyNodes = new MimeBuilder('multipart/alternative');
308308
for (const [type, content] of Object.entries(body)) {
309309
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
310-
bodyNodes.appendChild(Mime.newContentNode(MimeBuilder, type, content!.toString()));
310+
bodyNodes.appendChild(Mime.newContentNode(MimeBuilder, type, Str.with(content!)));
311311
}
312312
const signedContentNode = new MimeBuilder('multipart/mixed');
313313
signedContentNode.appendChild(bodyNodes);

extension/js/common/core/msg-block-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class MsgBlockParser {
132132
let { blocks, normalized } = MsgBlockParser.detectBlocks(decryptedContent);
133133
for (const block of blocks) {
134134
if (block.type === 'publicKey') {
135-
const armored = block.content.toString();
135+
const armored = Str.with(block.content);
136136
foundPublicKeys.push(armored);
137137
normalized = normalized.replace(armored, '');
138138
}

extension/js/common/ui/key-import-ui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class KeyImportUi {
165165
const firstPrv = MsgBlockParser.detectBlocks(utf).blocks.filter(b => b.type === 'privateKey')[0];
166166
if (firstPrv) {
167167
// filter out all content except for the first encountered private key (GPGKeychain compatibility)
168-
prv = await KeyUtil.parse(firstPrv.content.toString());
168+
prv = await KeyUtil.parse(Str.with(firstPrv.content));
169169
}
170170
} else {
171171
try {

0 commit comments

Comments
 (0)