Skip to content
Merged
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
3 changes: 2 additions & 1 deletion extension/js/common/api/flowcrypt-website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { Api } from './shared/api.js';
import { Browser } from '../browser/browser.js';
import { Url } from '../core/common.js';
import { CatchHelper } from '../platform/catch-helper.js';

namespace FlowCryptWebsiteRes {
Expand All @@ -11,7 +12,7 @@ namespace FlowCryptWebsiteRes {

export class FlowCryptWebsite extends Api {
public static pubKeyUrl = (resource: string) => {
return `https://flowcrypt.com/pub/${encodeURIComponent(resource)}`;
return `https://flowcrypt.com/pub/${Url.encodeEmailAddressForPathSegment(resource)}`;
};

public static retrieveBlogPosts = async (): Promise<FlowCryptWebsiteRes.FcBlogPost[]> => {
Expand Down
8 changes: 4 additions & 4 deletions extension/js/common/api/key-server/attester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';

import { Api } from './../shared/api.js';
import { Dict, Str } from '../../core/common.js';
import { Dict, Str, Url } from '../../core/common.js';
import { PubkeysSearchResult } from './../pub-lookup.js';
import { AjaxErr, ApiErr } from '../shared/api-error.js';
import { ClientConfiguration } from '../../client-configuration';
Expand Down Expand Up @@ -74,7 +74,7 @@ export class Attester extends Api {
if (!this.clientConfiguration.canSubmitPubToAttester()) {
throw new Error('Cannot replace pubkey at attester because your organisation rules forbid it');
}
await this.pubCall(`pub/${encodeURIComponent(email)}`, pubkey, { authorization: `Bearer ${idToken}` });
await this.pubCall(`pub/${Url.encodeEmailAddressForPathSegment(email)}`, pubkey, { authorization: `Bearer ${idToken}` });
};

/**
Expand All @@ -86,7 +86,7 @@ export class Attester extends Api {
if (!this.clientConfiguration.canSubmitPubToAttester()) {
throw new Error('Cannot replace pubkey at attester because your organisation rules forbid it');
}
return await this.pubCall(`pub/${encodeURIComponent(email)}`, pubkey);
return await this.pubCall(`pub/${Url.encodeEmailAddressForPathSegment(email)}`, pubkey);
};

public welcomeMessage = async (email: string, pubkey: string, idToken: string | undefined): Promise<{ sent: boolean }> => {
Expand All @@ -110,7 +110,7 @@ export class Attester extends Api {

private doLookup = async (email: string): Promise<PubkeysSearchResult> => {
try {
const r = await this.pubCall(`pub/${encodeURIComponent(email)}`);
const r = await this.pubCall(`pub/${Url.encodeEmailAddressForPathSegment(email)}`);
return await this.getPubKeysSearchResult(r);
} catch (e) {
if (ApiErr.isNotFound(e)) {
Expand Down
4 changes: 4 additions & 0 deletions extension/js/common/core/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ export class Url {
return link;
};

public static encodeEmailAddressForPathSegment = (email: string) => {
return encodeURIComponent(email).replace(/%40/gi, '@');
};

public static removeParamsFromUrl = (url: string, paramsToDelete: string[]) => {
const urlParts = url.split('?');
if (!urlParts[1]) {
Expand Down
Loading