Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 3b13eb7

Browse files
committed
Prefer URL constructor over url dependency
1 parent 9d45a37 commit 3b13eb7

File tree

3 files changed

+3
-16
lines changed

3 files changed

+3
-16
lines changed

src/HtmlUtils.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import _linkifyElement from 'linkifyjs/element';
2525
import _linkifyString from 'linkifyjs/string';
2626
import classNames from 'classnames';
2727
import EMOJIBASE_REGEX from 'emojibase-regex';
28-
import url from 'url';
2928
import katex from 'katex';
3029
import { AllHtmlEntities } from 'html-entities';
3130
import { IContent } from 'matrix-js-sdk/src/models/event';
@@ -153,10 +152,8 @@ export function getHtmlText(insaneHtml: string): string {
153152
*/
154153
export function isUrlPermitted(inputUrl: string): boolean {
155154
try {
156-
const parsed = url.parse(inputUrl);
157-
if (!parsed.protocol) return false;
158155
// URL parser protocol includes the trailing colon
159-
return PERMITTED_URL_SCHEMES.includes(parsed.protocol.slice(0, -1));
156+
return PERMITTED_URL_SCHEMES.includes(new URL(inputUrl).protocol.slice(0, -1));
160157
} catch (e) {
161158
return false;
162159
}

src/utils/HostingLink.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import url from 'url';
18-
1917
import SdkConfig from '../SdkConfig';
2018
import { MatrixClientPeg } from '../MatrixClientPeg';
21-
import { urlSearchParamsToObject } from "./UrlUtils";
2219

2320
export function getHostingLink(campaign) {
2421
const hostingLink = SdkConfig.get().hosting_signup_link;
@@ -28,11 +25,8 @@ export function getHostingLink(campaign) {
2825
if (MatrixClientPeg.get().getDomain() !== 'matrix.org') return null;
2926

3027
try {
31-
const hostingUrl = url.parse(hostingLink);
32-
const params = urlSearchParamsToObject(new URLSearchParams(hostingUrl.query));
33-
params.utm_campaign = campaign;
34-
hostingUrl.search = undefined;
35-
hostingUrl.query = params;
28+
const hostingUrl = new URL(hostingLink);
29+
hostingUrl.searchParams.set("utm_campaign", campaign);
3630
return hostingUrl.format();
3731
} catch (e) {
3832
return hostingLink;

src/utils/UrlUtils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ limitations under the License.
1616

1717
import * as url from "url";
1818

19-
export function urlSearchParamsToObject<T extends {}>(params: URLSearchParams) {
20-
return <T>Object.fromEntries([...params.entries()]);
21-
}
22-
2319
/**
2420
* If a url has no path component, etc. abbreviate it to just the hostname
2521
*

0 commit comments

Comments
 (0)